JavaScript Shorts: An Overview

Posted by

For Of – JavaScript

The For Of Loop in JavaScript

The for…of statement creates a loop iterating over iterable objects (including Array, Map, Set, arguments object and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property.

Here is an example of how the for…of loop can be used:


let colors = ["red", "green", "blue"];

for (let color of colors) {
  console.log(color);
}

In the above example, the for…of loop iterates over the colors array and logs each color to the console.

The for…of loop simplifies the process of iterating over iterable objects and is a powerful tool in JavaScript.

It is important to note that the for…of loop does not work with plain objects, as they are not iterable. For objects, the for…in loop should be used instead.

Overall, the for…of loop is a handy feature in JavaScript for easily iterating over iterable objects, making code more readable and efficient.

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Jvm0001
10 months ago

Vlw professor pela aula