title: How can I check if arrays are equal in javascript?
body: <p>Have a look at this code sample <a href="http://jsfiddle.net/rdaPZ/" rel="noreferrer">or go to the jsfiddle</a></p>
  
  <pre><code>function printRelation(a, b, out) {
      var text;
      if (a === b) {
          text = "a === b";
      } else if (a == b) {
          text = "a == b";
      } else {
          text = "a != b";
      }
      $('#' + out).text(text);
  }
  
  var a = [0, 0, 2], b = a;
  printRelation(a, b, 'out1');
  a = [0, 0, 2];
  b = [0, 0, 2];
  printRelation(a, b, 'out2');
  </code></pre>
  
  <p>I would have expected both tests to output <code>a === b</code>, but only the first one does. The second one outputs <code>a != b</code>. Can anyone explain this behaviour? How can I efficiently compare arrays in javascript?</p>