Hash table VS Objects


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?

The main difference is complexity: the goal of an hash table is to keep the complexity as closest to O(1) as possible, compared to O(n).

So if we are talking millions of record having this difference may matters…
In more common user cases an Object would be just fine.

Consider also that Map was added since ES6 :slight_smile:

Thanks for your reply.

But I don’t really understand How the time complexity of an object is O(n).
for example.

 let myObj = {mark: "mark@gmail.com", alan: "alan@gmail.com" .... };

Here to access any key in myObj Or to do any other operation time complextiy should be O(1) not O(n)

Sorry my previous post was not really clear, apologies.
The JS engine creates Object already as hash tables, pretty handy :slight_smile:

I assumed you were comparing them to other data stricture like arrays.

1 Like

Objects are Hash Tables. But Javascript abstracts away all the complicated understandings from the user, such as the hashing function.

Learn more at https://dev.to/loganwohlers/intro-to-hash-tables-js-objects-under-the-hood-26oa