javascript - Undefined key coming -
below code:
var xx=[]; xx['1'] ={'a':'bb','c':'dd'} debugger; document.log(xx); when print xx says undefined key

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'} 
this way wouldn't create sparse array.
Comments
Post a Comment