const deepClone = (obj) => { if (typeof obj !== "object" || obj === null) { return obj; } let result = obj.constructor === Array ? [] : {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { result[key] = typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key]; } } return result; } const obj1 = { name: "Alice", age: 20, hobbies: ["reading", "music"] }; const obj2 = deepClone(obj1); console.log(obj2); // { name: "Alice", age: 20, hobbies: ["reading", "music"] }