Removing array of items from an array with filter and custom function - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Removing array of items from an array with filter and custom 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() {/*www .  ja  v  a 2s .com*/
var a = [ 1,2,3,4,5,6,7,8],
    b = [ 6,7,8 ] 
removeItemsFromAThatAreListedInB(a, b);

function removeItemsFromAThatAreListedInB(a, b )
{
  a = a.filter(function(item) {
      return b.indexOf(item) === -1;
});
console.log( a );

}
    });

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

Related Tutorials