c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
JavaScript

How to filter odd number using from array in JavaScript?

| | JavaScript

In this article we will discuss implementing how to filter odd number using from array in JavaScript. Below example we are using a callback function Isodd it will result the odd numbers.

Example:

<script type="text/javascript">

    function Isodd(value, index, array) {

        if (value % 2 == 1) {
            return true;
        }
        else {
            return false;
        }
    }

        // Source array
    var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    // Pass the callback function asargument to the filter method

    var result = myArray.filter(Isodd);
   alert(result);
  </script>

 

Output: