I don't understand how work copying for arrays and what is the best way to copying objects from an array.
When I create a new array which is a copy of my existing array by spread operator or method slice() any actions still change the values in both arrays.
example:
let array = [{count: 10}, {count: 20}, {count: 30}, {count: 40}];
let newArray = array.slice();
newArray[1].count = 0;
// console.log(array[1].count === newArray[1].count);
// > true
This means that I should use JSON.parse(JSON.stringify(array))?
example:
let array = [{count: 10}, {count: 20}, {count: 30}, {count: 40}];
let arrayByJSON = JSON.parse(JSON.stringify(array));
arrayByJSON[1].count = 5;
// console.log(array[1].count === arrayByJSON[1].count)
// false