I’m new to data structure and I’m learning it in Javascript.
My Question is: Why do we need hash tables when we 've objects in javascript? Can anybody give me a situation where hash tables will be more useful than objects?
"Hashtable" is called different things in different languages. Java has Hashtable
and HashMap
, Ruby has Hash
, Python has dict
... in JavaScript, it's called Map
.
Objects' keys are limited to strings; Map
keys can be anything.
Objects support inheritance; a Map
only contains what is specifically put into it.