const deepClone = (obj: any) => { if (obj === null) return null; let clone = { ...obj }; Object.keys(clone).forEach( (key) => (clone[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]) ); return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone; }; const deepClone = (obj: any) => { if (obj === null) return null; let clone = { ...obj }; Object.keys(clone).forEach( (key) => (clone[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]) ); return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone; }; const deepClone = (obj: any) => { if (obj === null) return null; let clone = { ...obj }; Object.keys(clone).forEach( (key) => (clone[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]) ); return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone; }; const deepClone = (obj: any) => { if (obj === null) return null; let clone = { ...obj }; Object.keys(clone).forEach( (key) => (clone[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]) ); return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone; }; const deepClone = (obj: any) => { if (obj === null) return null; let clone = { ...obj }; Object.keys(clone).forEach( (key) => (clone[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]) ); return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone; };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter