Using TypeScript, I am trying to manage a list of objects without relying on ngrx and with immutability. As an example, this is how I'm approaching it:
let items = <any>[];
let item1 = { n: 'toto' };
// ADD item1
items = [...items, item1];
// Find item
const item1Find = items.filter((v) => v.n == 'toto')[0];
// Update item
item1Find.n = 'titi';
// Update item with immutability
items = [...items, item1Find];
//
console.log('items', JSON.stringify(items)); // [{"n":"titi"},{"n":"titi"}]
However, the issue I'm facing is that I end up with duplicates of the modified object! Can anyone offer some assistance in understanding why this is happening?