title: javascript: how to get index of an object in an associative array?
body: <pre><code>var associativeArray = [];
  
  associativeArray['key1'] = 'value1';
  associativeArray['key2'] = 'value2';
  associativeArray['key3'] = 'value3';
  associativeArray['key4'] = 'value4';
  associativeArray['key5'] = 'value5';
  
  var key = null;
  for(key in associativeArray)
  {
      console.log("associativeArray[" + key + "]: " +  associativeArray[key]);        
  }
  
  key = 'key3';
  
  var obj = associativeArray[key];        
  
  // gives index = -1 in both cases why?
  var index = associativeArray.indexOf(obj); 
  // var index = associativeArray.indexOf(key);  
  
  console.log("obj: " + obj + ", index: " + index);   
  </code></pre>
  
  <hr>
  
  <p>The above program prints index: -1, why? Is there any better way to get index of an object in an associative array without using loops?</p>
  
  <p>What if I want to delete 'key3' from this array? the splice function takes first parameter as index which must be an integer.</p>