Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there equivalent to C++ `unordered_map` in javascript

From MDN, javascript provides Map which is C++ equivalent to std::map. Is there a similar equivalent to unordered_map (providing O(1) insertions/lookup/deletion on avg).

Edit: As the answers suggest, std::unordered_map is more closer to javascript Map than std::map.

like image 715
Abhijeet Khangarot Avatar asked Oct 26 '25 14:10

Abhijeet Khangarot


1 Answers

The equivalent of a JavaScript Map is the C++ unordered_map, as it provides sub-linear access (i.e. possibly logarithmic but constant in practice) and does not sort its keys. It keeps insertion order of elements for deterministic execution and cross-implementation compatibility, but it is not sorted.

There is no equivalent of the C++ map, which is implemented as a tree with comparable keys, in JavaScript.

like image 78
Bergi Avatar answered Oct 29 '25 05:10

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!