0
Why the ouput of this code is 40?
Why the output of this code is 40? Can someone explain it to me. thanks var arrTest = [10, 20, 30, 40, 50] [1, 3]; console.log(arrTest);
6 Answers
+ 3
Because the index of 40 is 3
+ 3
It's the same as
var arrTest = [10, 20, 30, 40, 50] [3];
console.log(arrTest);
or
var arrTest = [10, 20, 30, 40, 50];
console.log(arrTest[3]);
Only the last index will be used with comma separated indexes, so, the 1 is ignored.
+ 2
No, indices are 0 based.
0 1 2 3 4
[10, 20, 30, 40, 50]
+ 1
Why not index 30 is 3 ?
edit : is it because index starts from 0 ?
+ 1
Munawirul Hadi
In few Programming Language index start from 1 but in mostly language index start from 0.
0
Counting start from 0, not from 1