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

222
Vistas
Updating object key value problem (Javascript)

When prod is pushed into prodObj, description in all other similar objects are updated to its last instance. While prod itself is just fine and all keys description are with its own value

    let prodObj = [];    

for (let i = 0; i < product.length; i++){
    for (let j = 0; j < cartRegistry.length; j++){
        if ( cartRegistry[j].ProductId === (product[i]._id.toString()) ){
            
            var prod = product[i];
            prod.description = parseInt(cartRegistry[j].Quantity);
            
            console.log(prod);
            prodObj.push(prod);
        }
    }
}

prod ex: _id: new ObjectId("62a52831c42a0fb4730283f4")
name: 'RJ45',
image: 'cable.jpg',
description: '2',

_id: new ObjectId("62a52831c42a0fb4730283f4")
name: 'RJ45',
image: 'cable.jpg',
description: '1',

ProdObj which was supposed to have the same values updates both description keys to 1, the last instance of it
Same with all other objects except they have different values

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