loop inside a loop javascript code example
Example 1: for in loop javascript
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}
Example 2: javascript loops
JS Loops
for (before loop; condition for loop; execute after loop) {
}
for
The most common way to create a loop in Javascript
while
Sets up conditions under which a loop executes
do while
Similar to the while loop, however, it executes at least once and performs a check at the end to
see if the condition is met to execute again
break
Used to stop and exit the cycle at certain conditions
continue
Skip parts of the cycle if certain conditions are met
Example 3: for loop inside a for loop javascript
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]]);