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

141
Vistas
Use object assign to make a copy of object without object reference

I have an array of objects which I want to make a copy of so I can modify later and not affect the original.

const myArray = [
    {
      id: 111,
      name: 'Nikki',
    },
    {
      id: 222,
      name: 'Jimbo',
    },
    {
      id: 333,
      name: 'Frank',
    },
];

To make the copy Ive used this below which works but I still feels a bit hacky

const copyOfMyArray = JSON.parse(JSON.stringify(myArray));

I have seen Object.assign({}, obj) being suggested for this but when I try to use it as below and transform it later myArray is still affected.

const copyOfMyArray = Object.assign([{}], myArray)

Is there any way to use Object.assign so it removes the original object reference?

about 4 years ago · Juan Pablo Isaza
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