Я полагаю, мою проблему легко исправить, но, будучи новичком, я не могу туда добраться.
const arr1 = [
{ department: "Lebensmittel", id: "id6", product: "Nudeln", status: false },
{ department: "Ceralien", id: "id5", product: "Marmelade", status: false },
{ department: "Ceralien", id: "id3", product: "Müsli", status: false },
{ department: "Ceralien", id: "id4", product: "Honig", status: false },
{ department: "Molkereiprodukte", id: "id1", product: "Milch", status: false }
];
let testArr = [...arr1];
testArr.forEach(obj => (obj.status = "test"));
console.log(arr1, testArr)
Журнал показывает, что функции forEach () также применяются к arr1. Почему это так и как сохранить неизменяемость arr1?
arr1 = [
{ department: "Lebensmittel", id: "id6", product: "Nudeln", status: false },
{ department: "Ceralien", id: "id5", product: "Marmelade", status: false },
{ department: "Ceralien", id: "id3", product: "Müsli", status: false },
{ department: "Ceralien", id: "id4", product: "Honig", status: false },
{ department: "Molkereiprodukte", id: "id1", product: "Milch", status: false }
];
testArr = [
{ department: "Lebensmittel", id: "id6", product: "Nudeln", status: false },
{ department: "Ceralien", id: "id5", product: "Marmelade", status: false },
{ department: "Ceralien", id: "id3", product: "Müsli", status: false },
{ department: "Ceralien", id: "id4", product: "Honig", status: false },
{ department: "Molkereiprodukte", id: "id1", product: "Milch", status: false }
];