[英]Javascript : how to push into object's attribute
我有这样的事情:
var test={
arr : [1,2],
number : 5
}
(test.arr).push(3);
它说: "Uncaught TypeError: Cannot read property 'arr' of undefined "
。 那么如何将数字或字符串推入'test.arr'?
你需要做的:
test.arr.push(3);
所以:
var test={
arr : [1,2],
number : 5
}
test.arr.push(3);
console.log( test.arr ); //gives [1,2,3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.