I would like to make a deep copy (break references) without turning date objects into strings, how would I do that?
let a = [{
date: new Date()
}, {
name: 'John'
}];
// let b = a.slice(); // This copies the object reference, which is wrong (we want a COPY of the obejcts)
// let b = [...a]; // This copies the object reference, which is wrong (we want a COPY of the obejcts)
// let b = JSON.parse(JSON.stringify(a)); // This makes the date a string, which is wrong (we want date objects, not strings)
let b = a.slice();
a[1].name = 'PETER';
console.log(a);
// [ { date: 2020-06-08T09:10:32.530Z }, { name: 'PETER' } ]
console.log(b);
// [ { date: 2020-06-08T09:10:32.530Z }, { name: 'PETER' } ]
Here is a good answer on Javascript Deep Copying: Copy array by value