英文:
How to remove object properties from objects in array using map()
问题
let objArr = [ { "name" : "Rohan", "request": true}, { "name" : "Sohan", "request": true, "modify" : "today", "expire": "tomorrow"}, { "name" : "Mohan", "request": true, "modify" : "today", "expire": "tomorrow"} ];
const newArr = objArr.map(v => ({ ...v, oldName: v.name, newName: v.name + '_copy', newRecord: true, request: v.request }))
console.log(newArr)
英文:
let objArr = [ { "name" : "Rohan", "request": true}, { "name" : "Sohan", "request": true, "modify" : "today", "expire": "tomorrow"}, { "name" : "Mohan", "request": true, "modify" : "today", "expire": "tomorrow"} ];
const newArr = objArr.map(v => ({ ...v, oldName: v.name, newName: v.name + '_copy', newRecord: true }))
console.log(newArr)
How to remove expire, modify, from the array?
Only oldName
, newName
, newRecord
and request
should display, the rest we can disable/remove.
答案1
得分: 1
不要删除某些属性,可以仅复制所需的属性,如下所示:
const newArr = objArr.map(v => ({ oldName: v.name, newName: v.name, newRecord: true }));
英文:
Rather than deleting some attributes, you can copy only those properties which are required as shown below
const newArr = objArr.map(v => {oldName: v.name, newName: v.name, newRecord: true})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论