Avatar ·

The most efficient way to deep clone an object in JavaScript

Hello everyone! I'm new to JavaScript and encountered a problem when copying objects. I need to create a completely independent copy of an object so that changes to the copy do not affect the original. But regular assignment doesn't work — the copy just references the same object. Here's an example of my code: ```javascript const original = { name: "Alice", age: 30, address: { city: "Moscow", zip: 101000 }, hobbies: ["reading", "swimming"] }; // Trying to copy const copy = original; copy.name = "Bob"; copy.address.city = "Saint Petersburg"; console.log(original.name); // "Bob" — oops, changed! console.log(original.address.city); // "Saint Petersburg" — also changed! ``` I tried using `Object.assign()` and the spread operator `{...obj}`, but they only create a shal