How to check if an array contains another array?

后端 未结 6 1829
后悔当初
后悔当初 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:15

    Here is an ES6 solution:

    myArray.some(
        r => r.length == itemTrue.length &&
             r.every((value, index) => itemTrue[index] == value)
    );
    

    Check the JSFiddle.

    Take a look at arrow functions and the methods some and every of the Array object.

提交回复
热议问题