上代码:var key1 = 'abc';var data1 = 'DDDDDDDDDDD';var key2 = 'def';var data2 = 'GGGGGGGGGGG';var rst = { key1: data1, key2: data2
};console.log(rst);结果是:rst = { key1: DDDDDDDDDDD, key2: GGGGGGGGGGG
}我想得到这样的结果{
rst = { abc: DDDDDDDDDDD, def: GGGGGGGGGGG}请问该如何实现?
1 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
var key1 = 'abc';
var data1 = 'DDDDDDDDDDD';
var key2 = 'def';
var data2 = 'GGGGGGGGGGG';
var rst = {
[key1]: data1,
[key2]: data2
};
console.log(rst);
添加回答
举报
0/150
提交
取消