Loop through a 'Hashmap' in JavaScript

后端 未结 8 923
逝去的感伤
逝去的感伤 2020-12-08 09:37

I\'m using this method to make artificial \'hashmaps\' in javascript. All I am aiming for is key|value pairs, the actual run time is not important. The method below works fi

8条回答
  •  自闭症患者
    2020-12-08 10:12

    This is an old post, but one way I can think of is

    const someMap = { a: 1, b: 2, c: 3 };
    Object.keys(someMap)
    .map(key => 'key is ' + key + ' value is ' + someMap[key]);
    

    Should this way of iterating be used? Are there any issues with this approach?

提交回复
热议问题