JavaScript Array filter()
JavaScript Array filter()
The filter() method is used to create a new array filled with elements that pass a test provided by a function. It does not execute the function for empty elements and does not change the original array.
Syntax:-
Its syntax is:- array.filter(function(currentValue, index, arr), thisValue)
Return:-
Its return is:- an array containing elements that passed the test.
Further Explanation:-
Parameter | Description |
function() | Required. A function to run for each array element. |
currentValue | Required. The value of the current element. |
index | Optional. The index of the current element. |
arr | Optional. The array of the current element. |
thisValue | Optional. A value is passed to the function as this value. Default is undefined. |