0
[solved] Can someone explain the output of this code ?
var arr1 = [7,8,9]; var arr2 = arr1; arr2[0] = 8; console.log(arr1[0]); I don't understand why arr1[0] outputs 8 after arr2[0] has been changed to 8 !?
3 ответов
+ 1
Because of var arr2 = arr1;
+ 1
Glad you figured it out Pete!
0
Alright, so it seems that assigning arr1 to arr2 is not only passing arr1's values to arr2 (like it would with strings or numbers variables). It kind of links them together.. so 2 variable names for the same array.. somehow..
Still slightly confusing 😕 but I'll keep trying thanks