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.
data[i]['name' + i]to geti... It's nonsensical.data[i]['name' + i]is pointless. Why not just usedata[i].name?