es8 (es2017) Object.entries

const object1 = {
  a: 'somestring',
  b: 42
};

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}

// expected output:
// "a: somestring"
// "b: 42"

 

posted @ 2021-11-17 15:08  Redchar  阅读(29)  评论(0编辑  收藏  举报