111
rated 0 times
[
112]
[
1]
/ answers: 1 / hits: 24435
/ 12 Years ago, fri, october 19, 2012, 12:00:00
Possible Duplicate:
Javascript expression to define object’s property name?
I'm trying to add objects to an array, but I want to have the name and value to be dynamic. Here's an example:
(function(){
var data = [];
for(i=0; i<5; i++){
data.push({'name' + i: i});
}
console.log(data);
})()
I guess I can't use a variable for the property so I'm not sure what to do.
More From » arrays