JS中给一个对象动态追加key
var data = {};
data['name'] = "张三";
var variable = 'age';
data[variable] = 12;
data.gender = "男";
console.log(data); //{name: "哈张三", age: 12, gender: "男"}
var data = {};
data['name'] = "张三";
var variable = 'age';
data[variable] = 12;
data.gender = "男";
console.log(data); //{name: "哈张三", age: 12, gender: "男"}