0

Why is the length of an arrayper example [3] equals to 3 while we have [0] [1] [2] [3] so its length is 4

arrays

18th Apr 2018, 8:41 PM
Eya Rejeb
Eya Rejeb - avatar
4 Réponses
+ 2
in programming languages you count from 0 so in your example it is: 0 1 2 3
18th Apr 2018, 8:46 PM
TrueJu
TrueJu - avatar
+ 1
While working with arrays, the index number of each element within the array starts from 0. So in the example, the element 0 would have an index of 0, 1 with 1, 2, with 2, and 3 with 3. Therefore, by selecting the element at the third index within the array, you would be selecting 3. Hope this helped! d:
18th Apr 2018, 8:47 PM
Faisal
Faisal - avatar
0
in your exemple an array of [3] should have [0] [1] [2] so it's length is 3
20th Apr 2018, 2:00 PM
fares garrach
fares garrach - avatar
0
The length of an array means the number of elements in that array. In your example array[3] means it has 3 elements with indexes starting from 0 which are [0] [1] [2]
21st Apr 2018, 2:41 PM
Mohamed IHeb Ferjani
Mohamed IHeb Ferjani - avatar