【发布时间】:2012-11-24 03:54:27
【问题描述】:
最近在学习做javascript类,看到别人这样做类
var item = {
'a':{'b':1000,'c':2000,'d':3000} , //how to make a variable become an array?
myfunction : function(){
console.log(item.a.b); //and output item.a[1]?
}
};
item.myfunction();
但是可以将变量a 设为数组吗?并像那样输出一个变量item.a[1]?我试过了
var a=new Array('1000','2000','3000')
但是错误,我需要正确的语法。
【问题讨论】:
-
如果你不需要
'b'、'c'或'd',那么你应该可以使用你所拥有的,甚至更好:'a':[1000, 2000, 3000],
标签: javascript jquery html