This content originally appeared on DEV Community and was authored by Mykyta Yarmak
var a={},
b={key:'b'};
a[b]=123;
In this case, b as key is "[object Object]" - result of b.toString()
Therefore, every keys are same as "[object Object]" whenever Object passed into Array Key
In this case, we can solve this problem using ECMAScript 6 Maps
var a = new Map(),
b = {key: 'b'};
a.set(b, 123);
This content originally appeared on DEV Community and was authored by Mykyta Yarmak
Mykyta Yarmak | Sciencx (2022-04-19T11:56:49+00:00) JavaScript Array Key as Object Type. Retrieved from https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.