How can I use a variable's value in a variable name in JavaScript?
I have a dynamically allocated array and I'm making a switch function that
starts like this:
switch (Years['year'].StartDay) {
The function that it's in passes a value called year and has a value in
it, like this:
function CalendarData(year, month) {
var Years = new Object();
Years.['2013'].StartDay = 'Sunday';
switch (Years['year'].StartDay) {
case 'Sunday':
this.Day = 1;
break;
}
}
I would like to make a new Object and get the data from the object, like
this:
var CalendayDay = new CalendarData('2013','February');
The issue is it's not reading Years['year'].StartDay
No comments:
Post a Comment