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.

4
  • Does this answer your question? How do I remove an object from an array with JavaScript? Commented Feb 18, 2023 at 15:34
  • This is same i used but how to add element in this ? i want add and remove feature all together Commented Feb 18, 2023 at 15:39
  • also Remove property for all objects in array Commented Feb 18, 2023 at 15:40
  • The simplest is to reverse the destructuring logic listing the props to remove explicitly and using rest parameters to keep the rest and avoid repeating all the properties you want to keepobjArr.map(({modify, expire, ...v} => ({...v, oldName: v.name, })); etc. Commented Feb 18, 2023 at 15:42

1 Answer 1

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})
Sign up to request clarification or add additional context in comments.

1 Comment

this is a duplicate, please flag to close

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.