About
In this code snippet, we’ll check out the for of loop in Javascript.
You probably already know about the for and while loops. But there are two other very useful vriations of the for loop called the for of loop and for in loop.
The for of loop can be used to iterate throught values of iterable objects. Meanwhile the for in loop can be used to iterate through keys of an object.
Let’s see the example below.
Code:
let numbers = [ 1, 5, 7, 3, 6 ]; //Returns values of an object. for(const number of numbers) console.log(number); //Returns keys of an object(indexes of the array in this case). for(const number in numbers) console.log(number);