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

161
Views
How to select an object by highest property value

I have an object:

[
   {
      name: "first name",
      rolePosition: 85
   },
   {
      name: "second name",
      rolePosition: 91
   }
]

How to select an object with the highest rolePosition value? In this situation is 91

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

0

The problem can be solved with Array.reduce() as follows:

const arr = [{ name: "first name", rolePosition: 85 }, { name: "second name", rolePosition: 91 }];

const result = arr.reduce((prev, curr) => prev.rolePosition > curr.rolePosition ? prev : curr , {});

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

This is your solution.

const arr = [
   {
      name: "first name",
      rolePosition: 85
   },
   {
      name: "second name",
      rolePosition: 91
   }
];
const numbers = [];
arr.forEach(el => numbers.push(el.rolePosition));
const max = Math.max(...numbers);

console.log(max)

about 4 years ago · Juan Pablo Isaza Report

0

You can use Math.max, Array.prototype.find to create similar function _.maxBy lodash

const maxBy = (arr, func) => {
  const max = Math.max(...arr.map(func))
  return arr.find(item => func(item) === max)
}
maxBy([{ test: 1 }, { test: 2 }], o => o.test)
// { test: 2 }

// or use reduce
const maxItem = arr.reduce(function(a, b) { return a.rolePosition >= b.rolePosition ? a : b }, {})
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!