Efficient method of getting key from value in javascript
<p>First, this question is not a duplicate of <a href="http://stackoverflow.com/questions/6748226/most-efficient-method-to-get-key-for-a-value-in-a-dict">Most efficient method to get key for a value in a dict</a> for the inquirer there asked about python and also because I want to discuss if solution given below makes sense and if it is fine to go about such a problem.</p>

<p>So, let's suppose, I have following a following datastructure:</p>

<pre><code>{ 
   "one" : "1",
   "two" : "2",
   .
   .
   "hundred thousand" : "100000"
}
</code></pre>

<p>Now, I want to able to get key against a particular value (assuming that I will not have same values for different keys). One solution is to get key by iterating the data but how efficient can become our code if we structure our data as:</p>

<pre><code> data = [
    { 
       "one" : "1",
       "two" : "2",
       .
       .
       "hundred thousand" : "100000"
    },
    { 
       "1" : "one",
       "2" : "two",
       .
       .
       "100000" : "hundred thousand"
    }
   ]
</code></pre>

<p>So, now <code>data[0]."two"</code> can be used to get value of two. But, let's suppose there is a scenario in which I know the value as 999 and I want to know it's key so to get its key I will do <code>data[1]."999"</code> i.e. I will use the reversed data in data[1].</p>

<p>This solution is perhaps faster than iterating over data to find right key. What do you think?</p>
