⬅️ JavaScript

  • 🔗 Stack Overflow

  • structuredClone(value)

  • The returned value is a deep copy of the original value.

  • Since March 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

const mushrooms1 = {
  amanita: ["muscaria", "virosa"],
};
 
const mushrooms2 = structuredClone(mushrooms1);
 
mushrooms2.amanita.push("pantherina");
mushrooms1.amanita.pop();
 
console.log(mushrooms2.amanita); // ["muscaria", "virosa", "pantherina"]
console.log(mushrooms1.amanita); // ["muscaria"]