index 0 in the second level javascript arrays -
can please know why if second level entry in multidimensional javascript array returned undefined if level length equal 1 ?
example :
arr = array( array(1) ) the following return unlikely result : undefined, while it's suppose 1 (or @ least that's expect be)
console.log(arr[0][0]) but when have more record in level (length>1) :
arr = array( array(1,2) ) and try : console.log(arr[0][0]), returns 1 time.
explanation issue or why happening appreciated
thanks
you should consult documentation of array constructor:
arraylength
if argument passedarrayconstructor integer between 0 , 232-1 (inclusive), returns new javascript arraylengthset number.
array(1) not create array element 1, creates array of length 1 one element: undefined.
to have less ambiguous constructor, use array literal:
[[1]] this 1 array contains 1 array contains value 1.