What are the iterable statement in JS?

Asked 19-Jul-2021
Viewed 475 times

1 Answer


1

In other words, we call the loop statement as iterable statement.
JavaScript iterable statements are used to iterate a piece of code using while, while or for-in loops. It is mostly used to access the value in array. We use iterable statement because, if a line of code has to be executed multiple times, then we put that statement in the loop. by which it runs automatically
In JavaScript has five types of iterable statement.
  1. for loop
  2. while loop
  3. do-while loop
  4. for-in loop
  5. for-of loop

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>

What are the iterable statement in JS?