JS中给一个对象动态追加key

var data = {};
data['name'] = "张三";
var variable = 'age';
data[variable] = 12;
data.gender = "男";
 
console.log(data);  //{name: "哈张三", age: 12, gender: "男"}

posted @ 2022-07-28 09:12  夏雨言  阅读(1502)  评论(0编辑  收藏  举报