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

152
Views
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 answers
Answer question

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