deepCopy.ts 250 B

1234567891011121314
  1. export const deepCopy = (obj) => {
  2. if (obj === null || typeof obj !== 'object') {
  3. return obj;
  4. }
  5. const copy = Array.isArray(obj) ? [] : {};
  6. Object.keys(obj).forEach((key) => {
  7. copy[key] = deepCopy(obj[key]);
  8. });
  9. return copy;
  10. };