JavaScript 使用变量作为对象的key

369 阅读1分钟

把变量 key 作为obj的键:

const key = 'keyName';
const obj = { [key]: 'keyvalue' }
console.log(obj)

得到效果: image.png