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);

7th May 2020, 6:37 PM
Munawirul Hadi
Munawirul Hadi - avatar
6 odpowiedzi
+ 3
Because the index of 40 is 3
7th May 2020, 6:41 PM
A͢J
A͢J - avatar
+ 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.
7th May 2020, 6:44 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
No, indices are 0 based. 0 1 2 3 4 [10, 20, 30, 40, 50]
7th May 2020, 6:48 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Why not index 30 is 3 ? edit : is it because index starts from 0 ?
7th May 2020, 6:46 PM
Munawirul Hadi
Munawirul Hadi - avatar
+ 1
Munawirul Hadi In few Programming Language index start from 1 but in mostly language index start from 0.
7th May 2020, 7:04 PM
A͢J
A͢J - avatar
0
Counting start from 0, not from 1
7th May 2020, 6:49 PM
Александр Никитин
Александр Никитин - avatar