views:

21

answers:

1
 var contact = { varWorkExperiences: [{ Experience: "aaa" },Experience: "bbb"}]  };

I have a structure like this. I can use push method like this:

contact.varWorkExperiences.push({ Experience: "ccc"});

but I want to do this paramaticly

I cant do this:

var x = "Experience";
contact.varWorkExperiences.push({ x: "ccc"});

How can I solve this? I have to use push method in function but I can't pass attribute as a parameter.

+1  A: 
var x = "Experience";
var obj = {};
obj[x] = "ccc";
contact.varWorkExperiences.push(obj);
dmitko