This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer
Spreading is a common technique for copying objects in JavaScript:
- Spreading into an Array literal to copy an Array
- Spreading into an Object literal to copy a plain object
Spreading has one significant downside – it creates shallow copies: The top levels are copied, but property values are shared.
structuredClone()
is a new function that will soon be supported by most browsers, Node.js and Deno. It creates deep copies of objects. This blog post explains how it works.
This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer
Dr. Axel Rauschmayer | Sciencx (2022-01-16T00:00:00+00:00) structuredClone()
: deeply copying objects in JavaScript. Retrieved from https://www.scien.cx/2022/01/16/structuredclone-deeply-copying-objects-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.