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

100
Views
What's the most succinct syntax to preserve only specific keys from a large JavaScript object?

In other words, I want to clean objects by dropping most of their keys.

Say a third party API returns JSON with a large number of of attributes you don't care about.

obj = {
  name: ...,
  id: ...,
  description: ...,
  blah: ...,
  bloop: ...,
  blip: ...,
  ... 12 others
}

But you're only interested in, say, id and name.

I know there's spread syntax object destructuring that allows me to put these into separate variables.

const { id, name } = obj

Is there a way to transform obj into a new object that looks like the following without explicitly accessing every key and value and making an object out of those?

newObj = {
  id: ...,
  name: ...
}

I'm curious if there's a one-liner I can put into map to transform a whole array of these objects.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just destructure the wanted properties and use short hand properties for the object.

result = array.map(({ id, name }) => ({ id, name }));
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!