Testing for existence of enumeration value in a JavaScript associative array
<p>I have built an "enumeration" in javascript using the following syntax:</p>

<pre><code>MyEnum = {
    MY_VAL_1 : { name: "Value 1" },
    MY_VAL_2 : { name: "Value 2" },
    MY_VAL_3 : { name: "Value 3" }
};
</code></pre>

<p>I want to store a dictionary containing 0 or more of these enumeration values and I want to be able to test for the existence of any particular value in the dictionary. I also want to show the values that are not in the dictionary inside a dropdown, and the values that are in the dictionary in another dropdown, and have buttons that allow the user to add or remove values to or from the dictionary using these dropdowns. </p>

<p>I can get the dropdowns working, but I can't test for existence in the dictionary outside of a "for (x in MyEnum)" block. If I use:</p>

<pre><code>list[MyEnum.MY_VAL_1]
</code></pre>

<p>I always get false (I guess because the items are stored without the MyEnum namespace?). If I try:</p>

<pre><code>list[MY_VAL_1]
</code></pre>

<p>I just get an Uncaught ReferenceError.</p>

<p>How can I get this to work, or is there a better way to do this?</p>

<p>Here is a jsFiddle of what I've done so far: <a href="http://jsfiddle.net/jKfbh/3/" rel="nofollow">http://jsfiddle.net/jKfbh/3/</a></p>
