JS: Array.prototype.filter

By Xah Lee. Date: . Last updated: .
arrayX.filter(f)
Return a new array, with elements that f return true.

The function f is passed 3 args:

  1. currentElement
  2. currentIndex
  3. arrayX
const f_isEven = ((x) => (x % 2 === 0));

const xx = [7, 3, 4, 2];

console.log(xx.filter(f_isEven)); // [ 4, 2 ]

// original not changed
console.log(xx); // [ 7, 3, 4, 2 ]
arrayX.filter(f, thisArg)
Use thisArg for this Binding of f. If it is not given, undefined is used.

JavaScript, Loop, Iteration

BUY ΣJS JavaScript in Depth