When you do something like array2 = array1;
you are just setting array2
as a reference to array1
. To make a copy of array1 you need to do array2 = array1.slice();
Furthermore, you can not set Array elements with array1.value1 ='1';
. What you have done there is convert your array to an Object. So what you really should be doing is:
var array1 = [];
var array2 = [];
array1[0] = 1;
array2 = array1.slice();
array2[1] = 2;
No comments:
Post a Comment