动态引用Javascript数组名称而不使用Eval? [英] Dynamically referencing Javascript Array name without using Eval?

查看:62
本文介绍了动态引用Javascript数组名称而不使用Eval?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于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'))

但是eval不好,所以我该如何构造一个数组名然后引用它?

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

这里还有更多内容:

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

有什么想法吗?

谢谢.

推荐答案

它是一个全局变量,它将是window对象的一个​​属性:

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

window[calendarObject.id + '7']

这篇关于动态引用Javascript数组名称而不使用Eval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆