November 2017
Intermediate to advanced
386 pages
9h 22m
English
A common need is having to filter the elements of an array according to some condition. The .filter() method lets you inspect each element of an array, in the same fashion as .map(). The difference is that instead of producing a new element, the result of your function determines whether the input value will be kept in the output (if the function returned true) or if it will be skipped (if the function returned false). Also similarly to .map(), .filter() doesn't alter the original array, but rather returns a new array with the picked items.
See Figure 5.4 for a diagram showing the input and output:

Read now
Unlock full access