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

98
Vistas
Compare the object fields within array

Compare the age of the objects in an array and keep only the one with the highest age. I've gone through the solution which uses reduce function, but is there any other optimal way other than using reduce? I am new to javascript, and still learning the concepts.

array: [ { "name": "sample", "age": 22 },{ "name": "sample2", "age": 42 }]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can achieve this with sort:

const array = [ { "name": "sample", "age": 22 },{ "name": "sample2", "age": 42 }]

const max = array.sort((a, b) => {
  return b.age - a.age
})[0]

console.log([max])

about 4 years ago · Juan Pablo Isaza Denunciar
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