2 for loops in javascript code example
Example 1: nested loops js
var arr = [[1,2], [3,4], [5,6]];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
Example 2: javascript loop if statement
for (let i = 0; i < 10000; i++) {
console.log('huduiduin 100000 times');
}
Example 3: javascript for loop 5 times
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}
Example 4: nested loops js
function multiplyAll(arr) {
var product = 1;
for (var i=0; i<arr.length; i++ ){
for (var j=0; j<arr[i].length; j++){
product*=arr[j];
}
}
return product;
}
multiplyAll([[1,2],[3,4],[5,6,7]]);