JavaScript filter() Method
The filter() method filters the given array with the help of a function that tests each element in the sequence to be true or not.
The following example shows, how to filter odd elements in an array using a filter Method.
Example
var a=[1,2,3,4,5,6] function is_odd(x){ if(x%2!=0) return true else return false } //call 'square' function for each item in a using map var b=a.filter(is_odd); document.querySelector("#out").innerHTML=b;Try it Yourself