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

95
Views
Return Object Key based on Value

I need to return the key of an object based on the greatest value of its object[value]. For example:

const myObj = {
    a: 100,
    b: 200,
    c: 300
}

I need a function that would return c (given that c has the highest numerical value)

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

0

Object.keys(myObj).reduce((acm, current) => {
    if (acm) {
        return myObj[acm] > myObj[current] ? acm : current;
    }
    return current;
}, null);
about 4 years ago · Juan Pablo Isaza Report

0

const myObj = {
    a: 100,
    b: 200,
    c: 300
};
res = Object.keys(myObj).sort((b,a) => myObj[a]-myObj[b]);
console.log(res); // [ "c", "b", "a" ]
// for highest use res[0]
about 4 years ago · Juan Pablo Isaza Report

0

function fn(obj) {
    return Object.entries(obj).reduce((v, maximum) => maximum[1] < v[1] ? v : maximum)[0]
}
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!