It's perplexing that even after utilizing distances.slice()
, I end up modifying the original array when I make changes to the new copy. What could be causing this unexpected behavior?
var distances = [
['-1', '10', '-1', '31'],
['10', '-1', '10', '-1'],
['-1', '-1', '-1', '10'],
['15', '6', '-1', '-1']
];
for (var i = 0; i < 4; i++) {
console.log(distances, 'distances pairstop');
var sampleDistance = distances.slice()
sampleDistance[0][2] = ['fooo']
}