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

205
Views
How to find the higher numbers in an object in JavaScript?

I want to reach the higher numbers in an object.

let object1 = {
  a: 2,
  b: 2,
  c: 0,
  d: 3,
  e: 1,
  f: 1
}
// Need to get 2,2,3 above. The first 3 highest ones.
let object2 = {
  a: 7,
  b: 15,
  c: 1,
  d: 7,
  e: 4,
  f: 3
}
// 15,7,7 above.

But it is not like return > 1 because I cannot set an exact number; the object can be

let object1 = {
  a: 1,
  b: 1,
  c: 0,
  d: 2,
  e: 0,
  f: 0
}

I have tried it like keys.reduce but I could not reach out to a good solution.

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

0

let input = {
  a: 1,
  b: 1,
  c: 0,
  d: 2,
  e: 0,
  f: 0
}

console.log(Object.values(input).sort((x, y) => y - x).slice(0, 3));

You can use sort against the values of the object. First use Object.values to change your object values into an array then run a sort against it with a slice to fetch first 3 highest values.

Object.values(input).sort((x, y) => y - x).slice(0, 3);
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!