How to check if an array contains another array?

后端 未结 6 1809
后悔当初
后悔当初 2020-11-28 16:36

I needed 2d arrays, so I made nested array since JavaScript doesn\'t allow them.

They look like that:

var myArray = [
      [1, 0],
      [1, 1],
            


        
6条回答
  •  一向
    一向 (楼主)
    2020-11-28 17:05

    You can't do like that .instance you have to do some thing by your own .. first you have to do a foreach from your array that you want to search and run 'compareArray' function for each item of your array .

    function compareArray( arrA, arrB ){
    
        //check if lengths are different
        if(arrA.length !== arrB.length) return false;
    
    
        for(var i=0;i

提交回复
热议问题