For In Loop in JavaScript

Level 286 keystrokes

The for...in loop iterates over the enumerable properties of an object.

JavaScript code

// Create an object with two properties
1let obj = { a: 1, b: 2 };
// for...in loops through each key (property name) of the object
// key will be "a" then "b"
2for (let key in obj) {
// Access the value using bracket notation obj[key]
// + concatenates strings together
3 console.log(key + ": " + obj[key]);
4}

Output

a: 1
b: 2
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.

  • :× 3
  • ;× 2
  • "× 2
  • (× 2
  • )× 2
  • {× 2
  • }× 2
  • +× 2
  • ,× 1
  • .× 1

More JavaScript examples at level 2

← JavaScript typing practice