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

98
Views
I there an elegant way to re-assign deconstructed object values using ESNext

Lets say we have an object with some values

const objectWithSomeValues = {
    numbers: 12345,
    word: 'hello',
    valueIDontWantToBeDeconstructed: [1,2,3,4,{}, null]
}

And somewhere else in the code I'm deconstructing this object

const someNewObject = {}
const { numbers, word } = objectWithSomeValues 
/* and reassigning them to another */
someNewObject.numbers = numbers
someNewObject.word = word

Is there more elegant way to reassign those values to this object, maybe there is a one-liner that

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

0

List the valueIDontWantToBeDeconstructed and omit the others, and use rest syntax to collect those others into their own object.

const objectWithSomeValues = {
    numbers: 12345,
    word: 'hello',
    valueIDontWantToBeDeconstructed: [1,2,3,4,{}, null]
};
const { valueIDontWantToBeDeconstructed, ...newObj } = objectWithSomeValues;
console.log(newObj);

about 4 years ago · Juan Pablo Isaza Report

0

Here you go:

const { numbers, word } = objectWithSomeValues;

const someNewObject = { numbers, word };

console.log(someNewObject); // { numbers: 12345, word: 'hello' }

Alternatively,

const someNewObject = {}
const { numbers, word } = objectWithSomeValues
Object.assign(someNewObject, {numbers, word});

console.log(someNewObject); // { numbers: 12345, word: 'hello' }
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!