ScanSkill

for...of

The for…of loop is used to loop over arrays.

Syntax

for(let element in array) {
  // Statements
}

The for...of iterates over each element of an array, the element is present in the variable declared inside the small brackets of the for...of loop.

Example

const fruits = ['banana', 'apple', 'orange'];

for (const fruit of fruits) {
  console.log(fruit);
}
/* Prints:
banana
apple
orange
*/

The for…of loop loops over arrays. It gives the actual value of the object unlike the key given in the case of for…in loop. It doesn’t loop over objects.