JavaScript: 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. current_element
  2. current_index
  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.
BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Array

prototype