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

221
Views
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
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!