That revision tests the best case (looking for string "a") while the revision I picked tests the worst case (looking for string "xxx", which doesn't exist). I picked it just because it came up first in Google search. Testing in my browser (Safari 9.0.1, Mac OS X 10.10.5) still gives a 54x improvement to Object indexing, though.
Perhaps getting the first value in an array is faster than indexing an Object in your browser.
The point is, if the thing doesn't exist, this part of the program will be thousands of times slower, and will get slower as the list of roles grows. Meanwhile, the hash map will not.
I'm not a hardcore JS dev, but it probably has to do with the speed of objects vs. arrays. In most languages, arrays are significantly faster (because they're basically one contiguous block of memory).
Perhaps getting the first value in an array is faster than indexing an Object in your browser.
The point is, if the thing doesn't exist, this part of the program will be thousands of times slower, and will get slower as the list of roles grows. Meanwhile, the hash map will not.