Answers for "deep copy a object in javascript"

9

deep clone object javascript

JSON.parse(JSON.stringify(object))
Posted by: Guest on July-06-2020
4

clone javascript object

let clone = Object.assign({}, objToClone);
Posted by: Guest on February-19-2020
1

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
}
Posted by: Guest on August-11-2020

Code answers related to "deep copy a object in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language