JavaScript Array Key as Object Type

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…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » JavaScript Array Key as Object Type." Mykyta Yarmak | Sciencx - Tuesday April 19, 2022, https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/
HARVARD
Mykyta Yarmak | Sciencx Tuesday April 19, 2022 » JavaScript Array Key as Object Type., viewed ,<https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/>
VANCOUVER
Mykyta Yarmak | Sciencx - » JavaScript Array Key as Object Type. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/
CHICAGO
" » JavaScript Array Key as Object Type." Mykyta Yarmak | Sciencx - Accessed . https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/
IEEE
" » JavaScript Array Key as Object Type." Mykyta Yarmak | Sciencx [Online]. Available: https://www.scien.cx/2022/04/19/javascript-array-key-as-object-type/. [Accessed: ]
rf:citation
» JavaScript Array Key as Object Type | Mykyta Yarmak | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.