-1

Any idea how to iterate a hash map object in JavaScript?

I tried the code below but it is not working.

for(var key : hmap)
{Alert(key + hmap[keep]);}
4
  • Possible duplicate of Looping through a 'Hashmap' in JavaScript Commented Feb 18, 2016 at 2:09
  • It is not working because keep is not defined? Commented Feb 18, 2016 at 2:27
  • "I tried the code below" - I guess using syntax from another language was worth a try, but when it didn't work did you not think to read some javascript tutorials/documentation? Commented Feb 18, 2016 at 2:33
  • JavaScript is not Java. There is no hashmap, and if you actually checked your errors you would see Uncaught SyntaxError: Unexpected token :. Commented Feb 18, 2016 at 2:33

1 Answer 1

0
for (var key in hmap) {
   alert(key + ':' + hmap[key])
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.