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

201
Vistas
Updating an objects nested property in a for loop

I've looked around a good amount on stackoverflow and haven't found this question yet. I feel like I'm missing something obvious so it's possible the question exists and I couldn't find it. My issue is that I'm trying to create an array of objects with different id's. When I run the for loop and update the id's based on the value of i, the resulting array has id's that are all the same.

Here's a sample snippet -

const baseObj = {
    nestedId: {
      id: 1,
  }
}

const objArr = [];
for(let i=0; i<3; i++) {
    const newObj = {...baseObj}
    newObj.nestedId.id = i + 1;
    objArr.push(newObj)
}

The resulting array is full of objects with the same id

{
  id: 3
}

I'm unsure what to do so I can make each id be different. Any help greatly appreciated.

about 4 years ago · Santiago Gelvez
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