Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda