0

What is the output of this code and why?

arr=[1, 2, 3, 4]; arr[5]= 5; alert(arr.length);

29th Nov 2020, 8:03 PM
isaac nabil
isaac nabil - avatar
3 Answers
+ 1
6 Arrays use 0 indexing - first one is 0. So every place in array counts as +1. Here's the full array: arr = [1, 2, 3, 4, 0, 5] Index 4 is none^
29th Nov 2020, 9:12 PM
OverdrivedProgrammer
+ 1
I think he's just using the 0 as a placeholder. The array actually would look like, [1,2,3,4,,5] if you output it as a whole. The actual value held at index 4, I.E. arr[4] is undefined.
29th Nov 2020, 10:32 PM
ChaoticDawg
ChaoticDawg - avatar
0
From where the zero come from đŸ€”
29th Nov 2020, 9:51 PM
isaac nabil
isaac nabil - avatar