title: Comparing arrays in javascript where order doesn't matter
body: <p>I am learning Javascript, and I saw a function on SO for comparing arrays to check if they are same. However, my current function returns false if the two arrays are [string1,string2] &amp; [string2,string1]. Basically, the two positions are interchanged. The code is as follows: </p>
  
  <pre><code>function _compareArrays(arr1,arr2){
      var result = arr1 != null &amp;&amp; arr2 != null &amp;&amp; arr1.length == arr2.length &amp;&amp; arr1.every(function(element) {
              return arr2.indexOf(element);
          });
      return result ;
  }
  </code></pre>
  
  <p>However, I want these two arrays to be returned as same. So, I changed <code>.every</code> to <code>.indexOf()</code> and it seemed to work. But, I have a doubt, how exactly is the counter getting incremented here to make sure the comparison is being done for every element?
  I mean, like, in C++, we do,</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++)
      if (arr1[i] == arr2[i]
        cout&lt;&lt;"Elements are same\n";
  </code></pre>
  
  <p>Here, I have an explicit <code>i++</code> which increments the counter. How does it happen in the above function? </p>
  
  <p>Thanks! </p>