Loop through a 'Hashmap' in JavaScript

后端 未结 8 951
逝去的感伤
逝去的感伤 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:22

    Hash maps can be tricky, but quite useful. When iterating over one as you would an object, each key is a tuple with [key, value]:

    for (let key of map) {
        console.log('Key is: ' + key[0] + '. Value is: ' + key[1]);
    }
    

提交回复
热议问题