Question

Given that EVAL is Evil how do I create an Array name dynamically:

I have a bunch of Arrays and I need to reference different ones depending on what the user clicks.

This bit of code gives me the array object:

(eval(calendarObject.id + '7'))

But eval is bad, so how to do I construct an Array name and then reference it?

Here's a bit more context:

if (jQuery.inArray(String(checkinDate.getTime()/1000), 
(eval(calendarObject.id + '7'))) == -1 ) { //do stuff };

Any ideas?

thanks.

Was it helpful?

Solution

It it's aglobal variable, it will be a property of the window object:

window[calendarObject.id + '7']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top