I'm having trouble figuring out how to properly copy an array along with all its elements.
In my model, I have a name and options, both of which are strings.
This is what I currently have:
const myArrayToDuplicate = [myModel, myModel, myModel]
My attempt to duplicate the array is like this:
const duplicate = Object.assign([], myArrayToDuplicate);
console.log(duplicate === myArrayToDuplicate) //false
console.log(duplicate[0] === myArrayToDuplicate[0]) //true -> not desired
Then I tried:
duplicate[0] = Object.assign(myArrayToDuplicate[0])
//still true
Could someone advise me on the correct way to achieve this task?