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

149
Views
Cómo seleccionar un objeto por el valor de propiedad más alto

tengo un objeto:

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

¿Cómo seleccionar un objeto con el valor más alto rolePosition ? En esta situación es 91

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

0

El problema se puede resolver con Array.reduce() de la siguiente manera:

 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

Esta es tu solución.

 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

Puede usar Math.max , Array.prototype.find para crear una función similar _.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!