Array.filter()

Creates a new array with all elements that pass the provided testing function.

Syntax

javascript
array.filter(callback(element, index, array))

Example

javascript
const nums = [1, 2, 3, 4, 5];
const evens = nums.filter(n => n % 2 === 0);
// [2, 4]