filter()

Description

With filter() you can apply a conditional expression to a list and only keep elements where the filter return true.

Example

[true, true, false].filter(value => value != true)

This filters out all the true values in the list evaluating to [false].

[1, 4, 2, 1, 3, 1, 4].filter(number => number > 2)

This removes elements smaller or equal to 2 from the list evaluating to [4, 3, 4].

Last updated

Was this helpful?