I want to create a copy of an array using the map function, but instead, I get the same reference. I don't understand why. I would like to have an alternative way to create a copy of an array.
I used the map function to create a copy of the original array and then used the filter function on the copy to mutate a single element. I would expect that the original array would not be mutated, but it actually is.
Can someone give me background info on why this is happening and also the right way to really copy an array, creating a reference to a different object?
const arr = [{name: 'hello'}, {name: 'world'}]
const arr2 = arr.map(i => i)
const [partial] = arr2.filter(i => i.name === 'hello')
partial.name = 'HELLO'
arr2[0].name === 'HELLO' // true
arr[0].name === 'HELLO' // true