Javascript - .filter()
Code Life
By Pierre Marsaa
Keeping Only Some Elements
You just learned that map transforms every element. filter selects some of them.
Its callback returns true to keep an element, false to drop it:
↗️
Loading editor...
↶
↷
The result is a new array with only the approved elements, in their original order. The original array is untouched.
Loading editor...
Verify