Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda