Skip to content

Instantly share code, notes, and snippets.

View m-sakthi's full-sized avatar

Sakthivel M m-sakthi

View GitHub Profile
@m-sakthi
m-sakthi / deepCloneObject.js
Created February 28, 2023 15:10
Deep clone of object
const deepClone = (obj) => {
if (obj === null || typeof obj !== "object") return obj;
let clone = Array.isArray(obj) ? [] : {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
clone[key] =
obj[key] instanceof Date
? new Date(obj[key].getTime())
: deepClone(obj[key]);
}