.filter() Method
Use the .filter()
method to filter out certain elements. In this example we're going to filter even numbers.
Output
In our function we used the remainder operator %. So, if any element is divisible by two, it is considered even. Otherwise we filter it out. You could similarly filter odd numbers by adding an exclamation point before the ==.
Last updated