0
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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jacob
  • 11
  • 1
  • Does this answer your question? [How do I remove an object from an array with JavaScript?](https://stackoverflow.com/questions/3396088/how-do-i-remove-an-object-from-an-array-with-javascript) – 697 Feb 18 '23 at 15:34
  • This is same i used but how to add element in this ? i want add and remove feature all together – jacob Feb 18 '23 at 15:39
  • also [Remove property for all objects in array](https://stackoverflow.com/questions/18133635/remove-property-for-all-objects-in-array) – pilchard Feb 18 '23 at 15:40
  • The simplest is to reverse the destructuring logic listing the props to remove explicitly and using [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#rest_property) to keep the rest and avoid repeating all the properties you want to keep`objArr.map(({modify, expire, ...v} => ({...v, oldName: v.name, }));` etc. – pilchard Feb 18 '23 at 15:42

1 Answers1

1

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})
  • this is a [duplicate](https://stackoverflow.com/questions/44888732/remove-specific-properties-from-array-objects-in-node-js), please flag to close – pilchard Feb 18 '23 at 15:38