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

74
Vistas
Clone object within object

I have this object:

var a={
    objectFoo:{member1:"x",member2:"y"}
}

I want to make it have an additional identical child:

{
     objectFoo:{member1:"x",member2:"y"}
    ,objectBar:{member1:"x",member2:"y"}
}

If I do an assigment:

a.objectBar=a.objectFoo

it creates an unwanted link.

The way I handle it now is:

a.objectBar=JSON.parse(JSON.stringify(a.objectFoo))

This works, but in my novice mind feels wrong. It's like I am instructing the machine to do complex parsing stuff instead of just moving data from one point to another. Is my thinking too low level for javascript? Or is there a better way to do this?

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