Java Reference
In-Depth Information
filter()
The filter() method returns a new array that only contains items from the original ar-
ray that pass return true when passed to the callback. For example, we can filter an array of
numbers to just the even numbers using the following code:
var numbers = [2, 7, 6, 5, 11, 23, 12]
numbers.filter( function(number) {
return number%2 === 0; // this returns true if the
number is even
});
<< [2, 6, 12]
There are other array methods that use callbacks that are worth investigating such as re-
duceRight() , every() , and some() . More information about them can be found at
the Mozilla Developer Network .
 
Search WWH ::




Custom Search