+ 2
Why the Other One with (arr[k]) is 1, 2, 3 but the Other One with Just (k) is 0, 1, 2?
• First One var arr = [1, 2, 3]; for (let k = 0; k < arr.length; k++) { document.write(arr[k]); } • Second One var arr = [1, 2, 3]; for (let k = 0; k < arr.length; k++) { document.write(k); - Good day, pals. Just asking why the output of First One is 1, 2, 3 is not the same at the Second One?
2 ответов
+ 3
Jonathan Pizarra, thank you, man.
+ 6
In the first one, you are accessing and printing the values of arr using k which are:
k = 0 >> arr[0] >> 1.
k = 1 >> arr[1] >> 2.
k = 2 >> arr[2] >> 3.
so the output is 1, 2, 3.
On the second one, you are only printing the values of k which are:
k = 0.
k = 1.
k =2 .
therefore 0, 1, 2.