deep clone object javascript
JSON.parse(JSON.stringify(object))
clone javascript object
let clone = Object.assign({}, objToClone);
how to deep copy an object in javascript
const obj1 = { a: 1, b: 2, c: 3 };
// this converts the object to string so there will be no reference from
// this first object
const s = JSON.stringify(obj1);
const obj2 = JSON.parse(s);
deep clone javascript object
const deepCopyFunction = (inObject) => {
let outObject, value, key
if (typeof inObject !== "object" || inObject === null) {
return inObject // Return the value if inObject is not an object
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {}
for (key in inObject) {
value = inObject[key]
// Recursively (deep) copy for nested objects, including arrays
outObject[key] = deepCopyFunction(value)
}
return outObject
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us