I encountered a problem where I had to create a hashmap using an empty Object.
An object is only really viable if you are using strings (or symbols) as keys. Anything else is coerced to a string with .toString() including numbers.
So consider using a Map instead (it's an iterable so it can be directly iterated).
The Map object holds key-value pairs and remembers the original insertion
order of the keys. Any value (both objects and
primitive values) may be used as
either a key or a value.
An object is only really viable if you are using strings (or symbols) as keys. Anything else is coerced to a string with
.toString()
including numbers.So consider using a Map instead (it's an iterable so it can be directly iterated).
Map - JavaScript | MDN
The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
Makes sense, thank you so much :)