1.将数组转换为对象
let arr = [{key: name, value: '张三'}, {key: age, value: 18}]
function arrToObj(arr) {
let obj = {}
arr.map(item => {
obj[item.key] = item.value;
})
console.log(obj) // {name: '张三', age: 18}
}
arrToObj(arr);
2.将obj2的值赋值给obj1
let obj1 = {name: '张三',age: 18}, obj2 = {}
for(let i in obj1) {
obj2[i] = obj1[i]
}
console.log(obj2) // {name: '张三', age: 18}