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

152
Views
Is there a way to generate an object from another object by taking all its properties with except of one?

Having the initial object of this shape:

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', ..., z: 'z' };

The result should contain all properties but without 'b' for example. I know there is a method like

const result = (({ a, b, c, d, ..., z }) => ({ a, c, d, ..., z }))(initial)

but in the case of an object with too many properties it's too much code.

Is there a shorter way to do that?

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

0

Clone the object and delete the property:

const result = {...initial};
delete result.b;
about 4 years ago · Juan Pablo Isaza Report

0

Use Object.entries() to convert the object to an array. Use filter() to skip that element of the array. Use Object.fromEntries() to convert that result back to an object.

const result = Object.fromEntries(Object.entries(initial).filter(([key, value]) => key != 'b'))

You can also use destructuring. List all the properties you want to remove explicitly in the destructuring target, then combine the rest into a new object with ....

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', z: 'z' };
const {b, ...result} = initial;
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

You can copy the object, then delete a key:

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', ..., z: 'z' };
const result = {...initial}; // copy the array
delete result.b;
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!