Immutable array

// Original items array
const items = [
  { id: "uuid-1", title: "Item 1" },
  { id: "uuid-2", title: "Item 2" },
  { id: "uuid-3", title: "Item 3" },
];

// Immutable Delete
const deleteId = "uuid-2";
const itemsAfterDelete = items.filter(item => item.id !== deleteId);

// Immutable Modify
const modifyId = "uuid-3";
const itemsAfterModify = itemsAfterDelete.map(item =>
  item.id === modifyId ? { ...item, title: "Modified Item 3" } : item
);

// Immutable Add
const newItem = { id: "uuid-4", title: "Item 4" };
const itemsAfterAdd = [...itemsAfterModify, newItem];

// Logging for demonstration
console.log(items); // Original items array remains unchanged
console.log(itemsAfterDelete); // Items after deletion
console.log(itemsAfterModify); // Items after modification

console.log(itemsAfterAdd); // Items after adding a new item