JS: Array.prototype.filter
arrayX.filter(f)
-
Return a new array, with elements that f return
true
.The function f is passed 3 args:
- currentElement
- currentIndex
- 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.