Filter an Array using JavaScript

Let’s see how to filter element values in an Array using JavaScript. We will use the JavaScript Array.Filter() to do so. Here’s the code to filter out all Even numbers from an array

Note: The filter() method is a new method added to the Array object with JavaScript 1.6 onwards (ECMAScript 5). It is not supported by all browsers like IE8. Hence we will first use if (!Array.prototype.filter) to check if the filter method is implemented in your browser, else provide an implementation for the filter() method, so that it works on most browsers like IE8.