Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to remove an element from array of objects during copy to another array in Javascript

After api calling I am getting an array of objects like this:

[{
 name: 'Apple',
 price: 120,
 buying_price: 80
},
{
 name: 'Banana',
 price: 20,
 buying_price: 10
},
{
 name: 'Orange',
 price: 100,
 buying_price: 70
}
]

Now I want to copy this result to another variable but don't want to copy buying_price. How can I do that?

Copy Variable will be like this:

[{
 name: 'Apple',
 price: 120
},
{
 name: 'Banana',
 price: 20
},
{
 name: 'Orange',
 price: 100
}
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let copied = original.map(v => {return {name: v.name, price: v.price}});

/*
Object destructuring
let copied = original.map(({name, price}) => ({name, price}));

*/
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!