@carbon/ibm-products
Version:
Carbon for IBM Products
26 lines (24 loc) • 798 B
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
//#region src/global/js/utils/deepCloneObject.js
/**
* Copyright IBM Corp. 2022, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const deepCloneObject = (objectToClone) => {
if (typeof objectToClone !== "object" || objectToClone === null) return objectToClone;
const clonedObject = Array.isArray(objectToClone) ? [] : {};
for (const key in objectToClone) {
const value = objectToClone[key];
clonedObject[key] = deepCloneObject(value);
}
return clonedObject;
};
//#endregion
exports.deepCloneObject = deepCloneObject;