← Volver

structuredClone() existe y copia en profundidad

Ya no hace falta JSON.parse(JSON.stringify(obj)). structuredClone copia en profundidad y además soporta Date, Map, Set y referencias circulares.

javascript
const copy = structuredClone(original);
copy.nested.value = 42; // original intacto
Referencia https://developer.mozilla.org/en-US/docs/Web/API/structuredClone