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

188
Views
¿Cómo puedo agregar una identificación dinámica a una matriz de objetos?

sugiero que tenga este objeto de matriz anidada

 let order={ a:1 b:2 service:[ 1:{a:1,b:3}, 2:{a:3,b:4} ] }

así que quiero insertar un objeto en la matriz de servicio con una nueva identificación dinámica, lo intenté

 let serviceOrder={a:5,b:6} let id=uuid4(); //example 4 let newSer={...order.service,id:serviceOrder} ```

pero entiendo esto

 service:[ 1:{a:1,b:3}, 2:{a:3,b:4}, id:{a:5,b:6} ]

mientras que quiero conseguir esto

 service:[ 1:{a:1,b:3}, 2:{a:3,b:4}, 3:{a:5,b:6} ]

Entonces, ¿cómo puedo hacer esto? Gracias de antemano para ayudar.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

prueba esto:

 let id=uuid4(); //example 4 let newSer={...order.service,[id]:serviceOrder}

cuando desee agregar una clave dinámica al objeto, puede usar [ ] y puede colocar su variable dentro de [ ]

about 4 years ago · Juan Pablo Isaza Report

0

También puedes hacerlo así.

 let newSer = {} newSer[id] = serviceOrder
about 4 years ago · Juan Pablo Isaza Report
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!