我希望你能将以下内容翻译成中文:
let myArray = [ {city: "NY"}, {status: 'full'} ];
转换为:
let myObj = { city: "NY", status: 'full' };
当我尝试这个时:
let newObj = {};
for (var i = 0; i < myArray.length; i++) {
(function(x) {
newObj = Object.assign(myArray[i]);
})(i);
}
它将最后一对键值分配给对象。
{ { city: 'NY' } }
。 - Explosion Pills