Using dynamic variable as key with multidimensional object
<p>I've gone bonkers hitting Stackflow and Google trying to find solutions, and finally am asking for ideas after being at this for a couple of hours. </p>

<p>This is my array:</p>

<pre><code>endangered = '#FFA500';
shutdown = '#FF0000';
active = '#00BB00';

// Build state array
var state = {};
state = {
        NV: {
            status: shutdown,
            name: 'Las Vegas Charter School for the Deaf',
            SchoolLink: 'http://www.lvcsd.org',
            SourceLink: 'http://www.lvrj.com/news/charter-school-for-deaf-signs-off-in-bankruptcy-141399423.html',
            ClosureDate: 'March 5, 2012',
            Comment: 'Closure due to bankruptcy. State also adopted exclusive mainstreaming approach.'
        },
        WY: {
            status: shutdown,
            name: 'Wyoming School for the Deaf',
            SchoolLink: 'http://www.wyomingdeaf.com/',
            SourceLink: 'http://trib.com/news/local/article_94be7523-5bc5-5031-97ee-9431a205cfe9.html',
            ClosureDate: '2000',
            Comment: 'School replaced by a mainstream school. State also adopted exclusive mainstreaming approach.'
        }
}
</code></pre>

<p>Accessing it then at this point would be something like:</p>

<pre><code>stateCode = 'NV';
currentColor = state[stateCode].status; 
</code></pre>

<p>It'd check the <b>state</b> array, look up the 'NV' array which has its own array, then finally look up the status, which also has its own variable, which references the color associated with that status. In this case, it'd be returning '#FF0000' for shutdown.</p>

<p>If I do the code like that, it fails saying 'undefined'. If I however do it like this:</p>

<pre><code>currentColor = state['NV'].status; 
</code></pre>

<p>It then works perfectly. But this defeats the purpose, as it becomes static. I need to be able to keep stateCode dynamic, as it's based on feedback from a function, and will always be changing. </p>

<p>I could do it like this:</p>

<pre><code>if(stateCode === 'NV') currentColor = state['NV'].status;
if(stateCode === 'WY') currentColor = state['WY'].status;
</code></pre>

<p>But it'd quickly become bloated. There has to be a better way to handle this. Any ideas?</p>
