JSFiddle - React, Tailwind, and code Playground
by Kai_Draord
JavaScript
function nestedCopy(array) {
return JSON.parse(JSON.stringify(array));
}
// undefineds are converted to nulls
console.log(nestedCopy([1, undefined, 2])) // -> [1, null, 2]
// DOM nodes are converted to empty objects
console.log(nestedCopy([document.body, document.querySelector('p')])) // -> [{}, {}]
// JS dates are converted to strings
console.log(nestedCopy([new Date()])) // -> ["2019-03-04T10:09:00.419Z"]