For Of Loop in JavaScript

Level 272 keystrokes

The for...of loop iterates over iterable objects like arrays, giving direct access to values.

JavaScript code

// Create an array with two color strings
1let colors = ["red", "green"];
// for...of loops through each value in the array
// c is assigned each element directly (not the index)
2for (let c of colors) {
// Print each color on a new line
3 console.log(c);
4}

Output

red
green
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 4
  • ;× 2
  • (× 2
  • )× 2
  • ,× 1
  • .× 1
  • [× 1
  • ]× 1
  • {× 1
  • }× 1

More JavaScript examples at level 2

← JavaScript typing practice