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
4 Answers
+ 2
in programming languages you count from 0 so in your example it is: 0 1 2 3
+ 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:
0
in your exemple an array of [3] should have [0] [1] [2] so it's length is 3
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]