I have a weird issue, where when I for example do this const data = [...businessCategories]; and make changes to the data variable like this data[itemIndex].selected = true;. What happens is the businessCategories variable get changed as well as data. I don't understand why this happpend since I copying values only not reference.
Asked
Active
Viewed 22 times
0
warCommander
- 198
- 1
- 9
-
You are making a **shallow** copy. `data` is a new array, but the values it holds in it are still references to the same objects referenced by `businessCategories`. – Quentin Jan 25 '22 at 13:59