Assign the specified key value in the object array to another array and change the key value (key name) in the object array

let arr = [{id:1, weChat:'test1'},{id:2, weChat:'test2'},{id:3, weChat:'test3'}]
let newArr = [];

arr.forEach((item)=>{
    let obj = {};
    for(let i=0; i <= arr.length; i++){
        obj.id = item.id;
        obj.name = item.weChat;
    }
    newArr.push(obj);
});
console.info(newArr);
//[{id:1, name:'test1'},{id:2, name:'test2'},{id:3, name:'test3'}]

 

Guess you like

Origin blog.csdn.net/Sunny_lxm/article/details/107638348