Home » JavaScript Array filter() Method

JavaScript Array filter() Method

by Online Tutorials Library

JavaScript Array filter() method

The JavaScript array filter() method filter and extract the element of an array that satisfying the provided condition. It doesn’t change the original array.

Syntax

The filter() method is represented by the following syntax:

Parameter

callback – It represents the function that test the condition.

currentvalue – The current element of array.

index – It is optional. The index of current element.

arr – It is optional. The array on which filter() operated.

thisArg – It is optional. The value to use as this while executing callback.

Return

A new array containing the filtered elements.

JavaScript Array filter() method example

Let’s see some examples of filter() method.

Example 1

Let’s see a simple filter() example to filter the marks of a student.

Test it Now

Output:

50,40,45,37  

Example 2

Let’s see one more array filter() example.

Test it Now

Output:

32,43  

Next TopicJavaScript Array

You may also like