If you just need a copy of the elements of the array, you can simply use the slice as follows:
a = [1,2,3] copyArray = a.slice(0) [1 , 2 , 3]
As for why you shouldn't use assignment, look here:
a = [1,2,3] b = a a.push(99) a [1,2,3,99] b [1,2,3,99]
If you copy an array, you do not have this problem:
a = [1,2,3] b = a.slice(0) a.push(888) a [1,2,3,888] b [1,2,3]
Pawel miech
source share