title: Is checking an object for a key more efficient than searching an array for a string?
body: <p>I'm creating a data structure that will contain that I will be using to repeatedly check to see if certain values are defined. I've come up with two possible solutions, and am wondering which is more efficient, or if there is a better way than either:</p>
  
  <p>1) Use an array: <code>keys = ['key1' , 'key2', 'key3']</code></p>
  
  <p>I can create an array like this and then use <code>jQuery.inArray(keyToCheck, keys) &gt; -1</code> to check and see if <code>keyToCheck</code> is in my array.</p>
  
  <p>2) Use an object: <code>keys = {key1 : 1, key2 : 1, key3: 1}</code></p>
  
  <p>I can create this object and then use <code>keys[keyToCheck] || 0</code> to see if <code>keyToCheck</code> is defined.</p>
  
  <p>What I'm not sure about is how searching an object is implemented in javascript, and whether or not it's more efficient than <code>jQuery.inArray</code>, which loops through an array. Is there a performance difference between these methods? Using jQuery isn't an issue for me since I already have it in my code for other reasons.</p>