1
What are the iterable statement in JS?
What are the iterable statement in JS?
Syntax:
for-loop
for(variable declaration; condition ; updation)
statement
while loop
variable declaration;
while(condition){
statement;
updation;
}
do-while loop
variable declaration;
do{
statement;
updation;
}while(condition);
for-in loop
for( variable in objects)
statement;
for-of loop
for (variable of iterable) {
statement
}
Example
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript For Loop</h2>
<p id='demo'></p>
<script>
const fruits = ['Apple', 'Banana', 'Graps', 'Kiwi', 'Mango', 'Orange'];
let text = '';
for (let i = 0; i < fruits.length; i++) {
text += fruits[i] + '<br>';
}
document.getElementById('demo').innerHTML = text;
</script>
</body>
</html>
