Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Bug] arr1.slice(0) returns referance to original array.

1392664786
Alex L.
Pro
Sheet Author
It is my understanding that using array.slice(0) should return a copy of the array but this is not the case with the API, if you edit a value in the array returned by slice it will edit the original as well.
1392829078
Lithl
Pro
Sheet Author
API Scripter
What is the type of the elements in the array? array.slice returns a shallow copy, not a deep copy. [new A(), new A(), new A()].slice(0)[0].foo = 'bar' will modify the value of foo in the first element of the original array, but [new A(), new A(), new A()].slice(0)[0] = new A() won't change the original array's contents.