If you have any query feel free to chat us!
Happy Coding! Happy Learning!
The for...of
loop is a newer way of iterating through arrays or other iterable objects in JavaScript. It was introduced in ES6 (ECMAScript 2015).
The for...of
loop works by iterating over the values of an iterable object, rather than iterating over its indices like the traditional for
loop or the forEach()
method. Here's an example of how to use a for...of
loop to iterate through an array:
cCopy code
const array = [1, 2, 3, 4, 5];
for (const element of array) {
console.log(element);
}
In the above example, the for...of
loop is used to iterate over each element of the array
, and the value of each element is printed to the console using console.log()
. The loop variable element
is declared with the const
keyword, which means that it cannot be reassigned within the loop.
The for...of
loop can also be used with other iterable objects, such as strings and maps. Here's an example of how to use a for...of
loop to iterate through the characters of a string:
cCopy code
const string = 'Hello, world!';
for (const char of string) {
console.log(char);
}
In this example, the for...of
loop is used to iterate over each character in the string
, and the value of each character is printed to the console using console.log()
.
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.