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

82
Views
Array find method without mutation

I have a function as below which finds a particular element in an array of objects and updates it:

async update(id, attrs){
    const records = await this.getAll();
    const record = records.find(record => record.id === id);
    Object.assign(record, attrs);
    await this.writeAll(records);

}

I was surprised to understand the find method returns a reference to the matching element in the records array whereas I was expecting that the record variable would just contain the value and changing it would not cause the original records array to get updated.

So my question is, what if I just want to retrieve the value from an object array but not a reference to the actual element? that is, I need to be able to update the returned value without mutating the original array.

about 4 years ago · Juan Pablo Isaza
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!