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

91
Views
Using flatMap and Math.max to get a certain field's highest value from obj

I am currently working with an object and trying to extract the highest value of duration field. I am trying to use both flatMap and Math.max to achieve this but so far I am getting a -Infinity result. I am also calling this flatMap twice which is likely not right :/. What would be the right approach to get the highest value of duration?

const users = [{
        name: 'User1',
        configuration: [{
                email: 'test1@email.com',
                duration: 60,
                active: true
            },
            {
                email: 'test2@email.com',
                duration: 180,
                active: false
            }
        ],
    },
    {
        name: 'User2',
        configuration: [{
                email: 'test3@email.com',
                duration: 120,
                active: true
            },
            {
                email: 'test4@email.com',
                duration: 30,
                active: true
            }
        ],
    },
    {
        name: 'User3',
        configuration: [{
                email: 'test5@email.com',
                duration: 300,
                active: true
            },
            {
                email: 'test6@email.com',
                duration: 10,
                active: true
            }
        ],
    },
];

Code:

const x = users.flatMap(user => user.configuration);
const y = x.flatMap(user => user.duration);
const highestvalue = Math.max(...Object.values(y).flat().flatMap(Object.values));
console.log(highestvalue);

Current Result:

-Infinity

Desired Result:

300
over 4 years ago · Santiago Trujillo
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!