Loop through an object – Javascript

Grindelwald, Suiza

Hi, there is a way to go through an object using the for/in loop. This loop is special for objects.

The for/in goes through the properties of an object.


// Object
const charMap = {
  a: 3,
  b: 5,
  c: 10,
  e: 50

for (let char in charMap) {
  // char is each key's (a, b, c, d, e) of the object
  console.log('char ==>', char);

  // charMap[char] is each value of the object
  console.log('charMap[char] ==>', charMap[char]);


Grindelwald, Suiza

By Cristina Rojas.