The filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
Syntax:
filter(callbackFn)
filter(callbackFn, thisArg)
callbackFn
A function to execute for each element in the array. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. The function is called with the following arguments:
element
The current element being processed in the array.
index
The index of the current element being processed in the array.
array
The array find() was called upon.
thisArg Optional
A value to use as this when executing callbackFn. See iterative methods.
Return value
The first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.