for…of Loop in JavaScript
In JavaScript, the for...of loop is a control flow statement introduced in ECMAScript 6 (ES6). It provides an easy and concise way to iterate over iterable objects, including arrays, strings, sets, maps, and more. The for...of loop simplifies the process of accessing and iterating through the elements of such collections. It is used to iterate over the elements of an iterable object, like array, string, etc.
The syntax of for…of loop in JavaScript is-
for(variable of iterable){
//code
}
Here's how the for...of loop in JavaScript works:
- The variable represents a new variable that is assigned the value of each element in the iterable object on each iteration of the loop.
- The iterable is any object that can be iterated over. It can be an array, a string, a set, a map, or any other object that implements the iterable protocol.
- The code block inside the loop is executed for each element in the iterable, with the variable holding the value of the current element.
500 Internal Server Error