Array.prototype.filter

Returns the elements of an array that meet the condition specified in a callback function.

Syntax

filter(predicate, thisArg?)

Parameters

Return value

New array after filtering.

Examples

[1, 2, 3, 4, 5].filter(x => x != 0 && x % 2 == 0)
[2, 4]
["coffee", "tea", "juice"].filter(drink => drink.length > 3)
["coffee", "juice"]
[0, 1, null, "ok", undefined].filter(x => x)
[1, "ok"]