filter

Modified on Fri, 18 Aug 2023

Description

Return a new array filled with elements that pass a test provided by the expression.

Syntax

filter(array, element, expression)

Parameters

Input ParameterTypeDescription
arrayArrayThe array filter() was called upon
elementanyThe current element being processed in the array
expressionexpressionA boolean expression to be run for each array element.

Return value

Type
Array<any>

Sample

ExampleResultDescription
filter([1, 2, 3, 4], x, x > 2)[3, 4]Returns the new filtered array.
find([{'name' : 'John', 'age' : 18},{'name' : 'Raj', 'age' : 25}, {'name' : 'Arun', 'age' : 20}], x, x.age > 18)[{'name' : 'Raj', 'age' : 25}, {'name' : 'Arun', 'age' : 20}]Returns all the user accounts with age greater than 18

To view all the List functions, click here.

See Also

map