ForEach array, if value is odd remove from array - Javascript Array

Javascript examples for Array:forEach

Description

ForEach array, if value is odd remove from array

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*  w w  w .j  a v  a2 s . c o m*/
var myArray = [1,2,3,4,5,6];
 var myArray = myArray.filter(function(item) {
          return item % 2 ==0  ?  false  :  true; // Return true if item is even and false other way round.
    });
console.log(myArray);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials