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

197
Views
Actualización de una propiedad anidada de objetos en un bucle for

He buscado mucho en stackoverflow y aún no he encontrado esta pregunta. Siento que me estoy perdiendo algo obvio, por lo que es posible que exista la pregunta y no pude encontrarla. Mi problema es que estoy tratando de crear una matriz de objetos con diferentes identificaciones. Cuando ejecuto el ciclo for y actualizo las identificaciones según el valor de i , la matriz resultante tiene identificaciones que son todas iguales.

Aquí hay un fragmento de muestra:

 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) }

La matriz resultante está llena de objetos con la misma identificación.

 { id: 3 }

No estoy seguro de qué hacer, así que puedo hacer que cada ID sea diferente. Cualquier ayuda muy apreciada.

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