JavaScript: Array.prototype.filter
arrayX.filter(f)
-
Return a new array, with elements that f return
true
.
The function f is passed 3 args: • current_element • current_index • arrayX. arrayX.filter(f, thisArg)
-
Use thisArg for this Binding of f. If it is not given,
undefined
is used.
const isEven = (x => ( x % 2 === 0 ) ) const arr = [7,3,4,2]; console.log( arr.filter ( isEven ) ); // [ 4, 2 ] // original not changed console.log( arr ); // [ 7, 3, 4, 2 ]