【发布时间】:2017-07-31 13:48:54
【问题描述】:
我想要这个代码:
var arr = [
{ key: 'foo', val: 'bar' },
{ key: 'hello', val: 'world' }
];
var result = arr.map((i) => ([i.key]: i.val)); //something like this
console.log(result);
返回:
{foo: 'bar', hello: 'world'}
这在 ECMA6 中可行吗?
【问题讨论】:
标签: javascript arrays object ecmascript-6