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

211
Vistas
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 Respuestas
Responde la pregunta

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 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