firecall
firecall

Reputation: 763

Dynamically referencing Javascript Array name without using Eval?

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.

Upvotes: 0

Views: 1887

Answers (1)

Greg
Greg

Reputation: 321698

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

window[calendarObject.id + '7']

Upvotes: 5

Related Questions