Hay 10 elementos en una matriz. ¿Qué hacer si quiero mostrar los primeros 5 elementos de la matriz usando el bucle forEach?
let arrays =[1, 2, 4, 6, 7, 44, 5, 7, 6] arrays.forEach(array =>{}) //Para mostrar los primeros 5 elementos de la matriz usando forEach loop, puede usar la instrucción if
const arrays = [1, 2, 4, 6, 7, 44, 5, 7, 6]; arrays.forEach(function(value, index, array) { if(index <= 4) { document.write(value + "<br>"); } });Donde parámetros:
https://www.w3schools.com/jsref/jsref_foreach.asp https://www.w3schools.com/js/js_if_else.asp