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

150
Vistas
how to push value in certain object in array in javascript?
let arr = [];

let obj {case:''};

after I did below code twice,

arr.push(obj)

I got arr below

[{…}, {…}]
0: {case: ''}case: 
1: {case: ''}
length: 2[[Prototype]]: Array(0)

and I just want to push certain value (ex. 'a') in first object.

so, I did below code

arr[0].case = 'a'

but, second object is also changed like below

(2) [{…}, {…}]
0: {case: 2}
1: {case: 2}

So, I want to know how to push certain value in certain object in an array.

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

0

Objects are stored as references, so to push the object twice and change one of them, you want to push them by:

arr.push(JSON.parse(JSON.stringify(obj)));

If you push your object to your array in this way, you should be able to change one item and not have the other change.

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