Skip to content
Advertisement

Loop through a ‘Hashmap’ in JavaScript

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 fine.

Are there any other ways to loop through this?

JavaScript

I run into a problem where this outputs a bunch of undefined keys after the first key, when the array only contains one entry. I have a feeling it is because the code is within a loop which uses i, even though when I follow in debug it shouldn’t be happening. I also cannot change i as the for loop seems to not understand the replaced var at all.

Anyone any ideas?

Advertisement

Answer

JavaScript

is not correct. It should be

JavaScript

which means “loop over the properties of a_hashmap, assigning each property name in turn to i

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement