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

151
Views
How to find object in array by property value and reasign it's value?

Lets say i have an array with objects like this;

let employees = [{Name: 'Misha', Age: 25}, {Name: 'Karing', Age: 26}, {Name: 'Stephan', Age: 24}]

And i need to find some item in this object and change it's value. In order to find value i can use filter

events.filter(e => (e.Age === 25));

Should it be like this ?

events.filter(e => (e.Age === 25)).Age= 26;

But have do modify this value then? Let say i found someone who is 25 and i need to increase age to 26 ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could map your array and change values on the fly. Here's one way of approaching it.

let employees = [{Name: 'Misha', Age: 25}, {Name: 'Karing', Age: 26}, {Name: 'Stephan', Age: 24}]
let changeAge = (from, to) => employees = employees.map(e => (e.Age === from ? {...e, Age: to} : e));

changeAge(25, 26);
console.log(employees)

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!