filter()
Produces a new arr from elements that satisfy the condition.
Syntax
arr.filter(element => condition)
Description
Tests the condition for each element; includes those that return true in the new array.
Returns
New (filtered) arr.
Example
Loading editor…
Expected output
[ 2, 4 ]
When to use?
Selecting only desired items from a list (even numbers, active users).