Remove items from dynamic array with filter function - Javascript Array

Javascript examples for Array:filter

Description

Remove items from dynamic array with filter function

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 ww  .  j a  va2  s .co m
var yourArray = [{
    id: 1,
    msg: "hello"
}, {
    id: 2,
    msg: "help"
}, {
    id: 1,
    msg: "bye"
}];
var newArr = yourArray.filter(function (item) {
    return item.id === 1;
});
console.log(newArr);
    }

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

Related Tutorials