[英]Add data to object array in javascript
I know I can do something like that: 我知道我可以这样做:
var data = [
{
name: 'test1',
value: 1
}
];
But I want to fill data
with dynamic values (from HTML). 但我想用动态值(来自HTML)填充data
。 So I will have var data = [];
所以我将有var data = [];
and how can I fill this one? 我怎么能填这个呢? I know, it must be somewhere on the internet, but I don not know the "right words" to search. 我知道,它必须在互联网上的某个地方,但我不知道要搜索的“正确的词”。
Note: data
have to be array filled with objects. 注意: data
必须用对象填充数组。
You can use the 'push' method. 您可以使用'推送'方法。
var a = []; a.push({item: 'a', value : 'a'}); console.log(a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.