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

366
Vistas
How to get the Index from the highest number. Using 'for'

Test array: [2, 3, 6, 7, 10, 1]; . Expected value on function return: 4 .

I did it like that but it's returning the value to me. I need the highest value index :

 function highestNumber(array) {
  
  let biggerNumber = 0;
  for (let index = 0; index < array.length; index += 1) {
    
    if (array[index] > biggerNumber) {
      biggerNumber = array[index]
    }
  }
  return biggerNumber;
}

highestNumber([2, 3, 6, 7, 10, 1]);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do it like this:

function highestNumber(array) {
  let returningIndex = 0;
  for (let index = 0; index < array.length; index += 1) {
    if (array[index] > array[returningIndex]) {
      returningIndex = index;
    }
  }
  return returningIndex;
}

highestNumber([2, 3, 6, 7, 10, 1]);
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