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

162
Vistas
What to do if i want to show the first 5 elements from the array by using forEach loop?

There are 10 elements in an array. What to do if i want to show the first 5 elements from the array by using forEach loop?

let arrays =[1, 2, 4, 6, 7, 44, 5, 7, 6]
 arrays.forEach(array =>{}) //
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To show the first 5 elements from the array by using forEach loop, you can use if statement

const arrays = [1, 2, 4, 6, 7, 44, 5, 7, 6];

arrays.forEach(function(value, index, array) {

    if(index <= 4) {
        document.write(value + "<br>");
    }

});

Where parameters:

  • Index = The index of the current element.
  • Value = The value of the current element.
  • Array = The array of the current element.

https://www.w3schools.com/jsref/jsref_foreach.asp https://www.w3schools.com/js/js_if_else.asp

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