How to loop through an object in JavaScript?

To loop through an object in JavaScript, use the for in loop.

Here's how you do it:

const object = {
  a: 1,
  b: 2,
  c: 3
};

// a 1
// b 2
// c 3
for (let key in object) {
  console.log(key, object[key]);
}