Reputation: 2683
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). So I will have 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.
Upvotes: 1
Views: 62
Reputation: 443
You can use the 'push' method.
var a = [];
a.push({item: 'a', value : 'a'});
console.log(a);
Upvotes: 2
Reputation: 77522
You can use .push method, like so
var data = [];
data.push({ name: 'test1', value: 1});
data.push({ name: 'test2', value: 2});
data.push({ name: 'test3', value: 3});
console.log(data);
Upvotes: 1