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


var data = {};
data['key1'] = "第一种";
var variable = 'key2';
data[variable] = "第二种";
data.key3 = "第三种";
console.log(data);  //{key1: "第一种",key2: "第二种",key3: "第三种"}

你可能感兴趣的:(JS中给一个对象动态追加key,value)