I have one object
item = { selectedItems: [] };
I did:
item1 = { ...item };
item2 = Object.assign({}, item);
item3 = Object.create(item);
but when I change selectedItems for item1 they are changed for all items. It's angular project
What's wrong? Or what's right way?
Or it's browser cache? I can't understand
You need a deep copy, example:
let newItem = JSON.parse(JSON.stringify(item));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With