array contains/includes sub array - Javascript Array Operation

Javascript examples for Array Operation:Array Search

Description

array contains/includes sub 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 ww.j  av a  2 s.  c o  m
var master = [1, 2, 3, 4, 5];
var sub = [2, 3];
Array.prototype.arrayContains = function(sub) {
  var self = this;
  var result = sub.filter(function(item) {
    return self.indexOf(item) > -1;
  });
  return sub.length === result.length;
}
console.log(master.arrayContains(sub));
    }

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

Related Tutorials