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

190
Vistas
How can I add a dynamic Id to array of object

suggest i have this object of nested array

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

so i want to insert object to service array with new dynamic id i tried that

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

but i get this

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

whereas i want to get this

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

so how i can do this thank in advance to help

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

try this:

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

when you want to add dynamic key to object you can use [ ] and you can place your variable inside [ ]

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also do it like this.

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