javascript - Undefined key coming -


below code:

var xx=[]; xx['1'] ={'a':'bb','c':'dd'} debugger; document.log(xx); 

when print xx says undefined key

enter image description here

https://jsfiddle.net/kjuhpgn2/

can let me know why "undefined" coming instead of "1" key?

edit:

i got that, should {} instead of []

var xx={};

array indexing start @ 0.

what it's saying have nothing @ index 0.

when set xx[1]=something starting array of size 0, set length of array 2, @ index 1 , undefined "filling" position @ index 0.

if want store dictionary, don't use array object map:

var xx={}; xx['1'] ={'a':'bb','c':'dd'} 

enter image description here

this way wouldn't create sparse array.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -