Accessing a JSON var wthout using item.item = string
<p>Here is the array</p>

<pre><code>var weekdayColor = {
        sunday : 'red',       // sunday
        monday : 'blue',      // monday
        tuesday: 'white',     // tuesday
        wednesday: 'black',    
        thursday: 'green',     
        friday: 'yellow',  
        saturday: 'orange'     
    }
</code></pre>

<p>I want to be able to do something along the lines of <code>weekcayColor[0]</code> to get <code>sunday</code>:</p>

<p>Here is the JavaScript I wrote for an interview which was already turned in.. I know there is an easier way to do this. The first var <code>weekdayColor</code> CANNOT BE CHANGED; also <code>weekdayColor.sunday</code> returns <code>red</code>.</p>

<p>Perhaps I am using the wrong date method or accessing the var incorrectly?</p>

<pre><code>var weekdayColor = {
        sunday : 'red',       // sunday
        monday : 'blue',      // monday
        tuesday: 'white',     // tuesday
        wednesday: 'black',     // wednessday
        thursday: 'green',     // thursday
        friday: 'yellow',    // friday
        saturday: 'orange'     // saturday
    }
    var weekday=new Array();
        weekday[0]="sunday";
        weekday[1]="monday";
        weekday[2]="tuesday";
        weekday[3]="wednesday";
        weekday[4]="thursday";
        weekday[5]="friday";
        weekday[6]="saturday";
    d = new Date;
    day = d.getDay();
    console.log(weekday[day]);
    a = weekday[day];
    function change(){
        var x = document.getElementById("weekday");
        x.innerHTML = a;
        x.style.color = weekdayColor[a];
    }
</code></pre>
