Hash Tables in JavaScript
mojavelinux.com
mojavelinux.com
var hash = Object.create(null)
creates an object free of inherited properties, this obviates most of the need for a wrapper class for the "I just want an associative array" case.For the "keys", "values", and "each" methods
In modern JS one could simply call
Object.keys(hash)
Object.keys(hash).map(function(key) { return hash[key] })
Object.keys(hash).forEach(function(key) { fn(key, hash[key]) })
respectively.Or as the article suggests, simply use a library like Lodash for this kind of general purpose iteration.
https://closure-library.googlecode.com/git-history/docs/clas...
https://developers.google.com/closure/library/docs/closurebu...
See: http://www.devthought.com/2012/01/18/an-object-is-not-a-hash... for more details.
So I'd +1 jestar_jokin's advice: use code that's been well-tested. The code presented in the original poster's "Hash Tables in Javascript" article does not look robust.