title: How to check if an array contains another array?
body: <p>I needed 2d arrays, so I made a nested array since JavaScript doesn't allow them.</p>
  <p>They look like this:</p>
  <pre><code>var myArray = [
    [1, 0],
    [1, 1],
    [1, 3],
    [2, 4]
  ]
  </code></pre>
  <p>How can I check if this array includes a specific element (i.e. one of these <code>[0,1]</code> arrays) in vanilla JS?</p>
  <p>Here is what I tried, with no success (everything returns <code>false</code>) <strong>(EDIT: I included the answers in the snippet)</strong>:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myArray = [
    [1, 0],
    [1, 1],
    [1, 3],
    [2, 4]
  ]
  
  var itemTrue = [2, 4];
  var itemFalse = [4, 4];
  
  function contains(a, obj) {
    var i = a.length;
    while (i--) {
      if (a[i] === obj) {
        return true;
      }
    }
    return false;
  }
  
  // EDIT: first answer's solution
  
  function isArrayInArray(x, check) {
    for (var i = 0, len = x.length; i &lt; len; i++) {
      if (x[i][0] === check[0] &amp;&amp; x[i][1] === check[1]) {
        return true;
      }
    }
    return false;
  }
  
  // EDIT: accepted answer's solution
  
  
  function isArrayInArray2(x, check) {
    var result = x.find(function(ele) {
      return (JSON.stringify(ele) === JSON.stringify(check));
    }) 
    return result !=null
  }
  
  console.log("true :" + myArray.includes(itemTrue));
  console.log("false :" + myArray.includes(itemFalse));
  
  console.log("true :" + (myArray.indexOf(itemTrue) != -1));
  console.log("false :" + (myArray.indexOf(itemFalse) != -1));
  
  console.log("true :" + contains(myArray, itemTrue));
  console.log("false :" + contains(myArray, itemFalse));
  
  // EDIT: first answer's solution
  console.log("true :" + isArrayInArray(myArray, itemTrue));
  console.log("false :" + isArrayInArray(myArray, itemFalse));
  
  
  // EDIT: accepted answer's solution
  console.log("true :" + isArrayInArray2(myArray, itemTrue));
  console.log("false :" + isArrayInArray2(myArray, itemFalse));</code></pre>
  </div>
  </div>
  </p>
  <p>It could look like duplicate but I couldn't find a similar question. If it is, feel free to tag it as such.</p>