I have an array data, that contains a nodeData object, which contains an id
I make 2 copies of the array:
const dropAboveData = data.slice();
const dropBelowData = data.slice();
and then I try to modify both copies of my 2 copied arrays differently
for(let i = 0; i<data.length; i++){
dropAboveData[i].nodeData.id = -1;
dropBelowData[i].nodeData.id = -2;
}
So for example if each record in data had data[i].nodeData.id = 0, at the end i would expect dropAboveData to contain all -1 for id, and dropBelowData to contain all -2 for id.
But instead it seems like data, dropAboveData, and dropBelowData all become arrays filled with -2.
Why is this happening? I though slice() makes a copy of the array so that i'm not accessing the same object?
data?