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

96
Views
Compare the object fields within array

Compare the age of the objects in an array and keep only the one with the highest age. I've gone through the solution which uses reduce function, but is there any other optimal way other than using reduce? I am new to javascript, and still learning the concepts.

array: [ { "name": "sample", "age": 22 },{ "name": "sample2", "age": 42 }]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve this with sort:

const array = [ { "name": "sample", "age": 22 },{ "name": "sample2", "age": 42 }]

const max = array.sort((a, b) => {
  return b.age - a.age
})[0]

console.log([max])

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!