How to iterate over a JavaScript object?

后端 未结 18 1706
失恋的感觉
失恋的感觉 2020-11-21 22:52

I have an object in JavaScript:

{
    abc: \'...\',
    bca: \'...\',
    zzz: \'...\',
    xxx: \'...\',
    ccc: \'...\',
    // ...
}

I

18条回答
  •  一生所求
    2020-11-21 23:11

    const o = {
      name: "Max",
      location: "London"
    };
    
    for (const [key, value] of Object.entries(o)) {
      console.log(`${key}: ${value}`);
    }
    

    Try online

提交回复
热议问题