javascript - Duplicate array -
I need to duplicate and manipulate an array variable, but for some reason when I created a new value array I'll put values in the original array pushing the value.
function test (point) {var newArray = currentChain; NewArray.push (dot); } In this situation, the point is being added to the current chain variable. Note that somewhere I am not setting currentChain as equal to newArray and there is no other variable in the script named newArray . Why is this being done?
To fix this, you need to clone your array. For example using the method:
var newArray = currentChain.slice (); This happens because your newer currentChain is an indicator for the array.
Comments
Post a Comment