How do you deep clone a JavaScript object?
I know there are various functions based on frameworks like JSON.parse(JSON.stringify(o)) and $.extend(t
JSON.parse(JSON.stringify(o))
$.extend(t
my addition to all the answers
function deepCopy(arr) { if (typeof arr !== 'object') return arr if (Array.isArray(arr)) return [...arr].map(deepCopy) for (const prop in arr) copy[prop] = deepCopy(arr[prop]) return copy }