When do variables made from arrays act as pointers to the array and when do they act as copies of the array?
For instance if I have an array named Array1
a1=Array1;
is a1 a copy or a pointer to the array.
If I modify a1 will it also modify Array1. By modify I mean change a value, push something into the array, sort, or any other way you could modify an array.
thanks,
x = [1,2,3]; y = x; y[0] = 7; console.log(x)will output7,2,3. arrays in JS are objects, and when you copy an object vianewobj = origobj, you're just creating a reference. you need to CLONE the array object to create a truly independent copy.