Remove array element by condition with for loop and if statement - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Remove array element by condition with for loop and if statement

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(){//from www  .ja v  a2  s. c  o  m
var ar = [ {num:1, str:"a"}, {num:2, str:"b"}, {num:3, str:"c"} ];
var newArray = [];
for (var i = 0, len = ar.length; i<len; i++) {
    if (ar[i].str == "b"){
       newArray.push(ar[i]);
    }
};
console.log(newArray);
    }

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

Related Tutorials