JavaScript: for...of Loop

Profile picture for user arilio666

For of is another alternative to for in, which is more accessible than for in. Here it fetches and returns the value of each element in an array.

Syntax

for(variable of object)
{
    //condition
}

Example:

let infinityStones = ['Soul', 'Time', 'Reality', 'Power', 'Mind', 'Space']

for(let stones of infinityStones)
{
    console.log(stones+ " Stone ")
}

Output:

Soul Stone
Time Stone
Reality Stone
Power StoneĀ 
Mind Stone
Space Stone

As you can see here, it caught the element's value directly after iterating through the infinityStones.