I have an array (arr1) that I push into another (arr2). I modify 'arr1' with a loop, but in the end, 'arr2' is also modified ! Why ? I would like to keep 'arr2' the same at the start. What is my mistake ?
arr1 = [1,2,3];
arr2 = [];
arr2.push(arr1);
$("#a1").html(arr1); // 1,2,3
$("#a2").html(arr2); // 1,2,3
// loop modifying ONLY 'arr1'...
for (i=0 ; i<arr1.length ; i++) {
arr1[i] = arr1[i]*3;
}
$("#b1").html(arr1); // 3,6,9
$("#b2").html(arr2); // 3,6,9 ... ??..incomprehensible !
// 'arr2' should not be modified ! The result should be 1,2,3
// Why is 'arr2' still modified ?