DEV Community

Discussion on: JavaScript Equality Checks

Collapse
ronakjethwa profile image
Ronak Jethwa Author

DeepClone Utility Method

function deepClone(obj) {
    let cloneObj = {};
    for(let prop in obj) {
        if(typeof obj[prop] === 'object') {
            cloneObj[prop] = deepClone(obj[prop]);
        } else {
            cloneObj[prop] = obj[prop];
        }
    }
    return cloneObj;
}

let clone = deepClone(user);
console.log(Object.is(user.sizes,clone.sizes));