Brah Pl
0
Q:

es6 loop through object

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

for (const property in object) {
  console.log(`${property}: ${object[property]}`);
}
8
const obj = {
  a: "aa",
  b: "bb",
  c: "cc",
};
//This for loop will loop through all keys in the object.
// You can get the value by calling the key on the object with "[]"
for(let key in obj) {
  console.log(key);
  console.log(obj[key]);
}

//This will return the following:
// a
// aa
// b
// bb
// c
// cc
1
for (var [key, value] of phoneBookMap) {
  console.log(key + "'s phone number is: " + value);
}
0

New to Communities?

Join the community