+ 6

I don't understand array in Javascript 😞😞

Can you help me expland this program. I think it so easy with someone but I can figure out how it work and go to output the result 0,1. Why it not 1,3??? . . var arr=[]; arr[0]=arr.length; arr[1]=arr.length + arr[0]; document.write(arr);

1st Jan 2018, 8:03 AM
Tran Huu Dang
Tran Huu Dang - avatar
4 Answers
+ 12
in the first statement arr.length =0 because there is not any element in the array so arr[0]=0 and in second statement arr[1]=1 because after first statement arr contain one element 0 so array length is 1 hence it shows 0,1 hope this is helpful for you
1st Jan 2018, 8:18 AM
Randeep Singh
Randeep Singh - avatar
+ 1
Because the array has a size of 0 until you add elements
1st Jan 2018, 8:12 AM
Jesse Bayliss
Jesse Bayliss - avatar
0
.
7th Jan 2018, 7:24 PM
xXDeathgasmXx
xXDeathgasmXx - avatar