TypeScript, Looping through a dictionary

后端 未结 8 840
慢半拍i
慢半拍i 2020-12-04 11:41

In my code, I have a couple of dictionaries (as suggested here) which is String indexed. Due to this being a bit of an improvised type, I was wondering if there any suggesti

8条回答
  •  庸人自扰
    2020-12-04 12:17

    < ES 2017:

    Object.keys(obj).forEach(key => {
      let value = obj[key];
    });
    

    >= ES 2017:

    Object.entries(obj).forEach(
      ([key, value]) => console.log(key, value)
    );
    

提交回复
热议问题