title: javascript indexOf not working as expected with array
body: <p>I am getting -1 from <code>myarray.indexOf(element)</code> even when element appears to be in myarray. </p>
  
  <p>Here's some code snippets:</p>
  
  <pre><code>function createChangeRecord( old_array, new_array ) {
      var nds = new_array.slice(0,new_array.length);
      var el, idx;
      if (...) {
          ...
      } else if ( old_array.length==new_array.length ) {
          for ( var i=0; i&lt;old_array.length; i++ ) {
              el = old_array[i];
              idx = nds.indexOf(el);
              if ( idx!=(-1) ) {
                  ...
              } else {
                  var a = "el: " + el + "; nds: " + nds + "; nds.indexOf(el): " + nds.indexOf(el);
                  alert( a );
                  ...
              }
          }
          ...
      }
      ...
  }
  </code></pre>
  
  <p>The alert shows me that nds does indeed contain el but the alert should only fire when idx==-1, which should only be true when nds does not contain el.</p>
  
  <p>I know I haven't given enough information to determine the specific issue in my case, but maybe someone can tell me some general reasons which might cause this behavior?</p>
  
  <p>Responses to a similar question suggested using jQuery inArray() instead of indexOf, but I want to know why indexOf doesn't work. Others suggested that indexOf is for strings, not arrays, but that's not true from the online docs I can find.</p>