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

103
Views
How to get highest 3 value from object array - ES6/JS

I simply want to get 3 highest price value objects as new array. How would I do that easily ?

For example i got array like this ..

const data = 
  [ { name: 'x', color: 'red',    price: 15 } 
  , { name: 'y', color: 'black',  price:  5 } 
  , { name: 'z', color: 'yellow', price: 25 } 
  , { name: 't', color: 'blue',   price: 10 } 
  , { name: 'n', color: 'blue',   price: 60 } 
  ] 

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

0

You can sort the array by the price property (with Array.sort) and get the first three items (with Array.slice):

const arr=[{name:"x",color:"red",price:15},{name:"y",color:"black",price:5},{name:"z",color:"yellow",price:25},{name:"t",color:"blue",price:10},{name:"n",color:"blue",price:60}];

const result = arr.sort((a,b) => b.price - a.price).slice(0, 3)

console.log(result)

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!