Skip to content

Commit b34f9d1

Browse files
authored
structuredClone
1 parent 582356c commit b34f9d1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
|42 | [Native text to speech JS](#Native-text-to-speech-JS)|
4949
|43 | [toFixed](#toFixed)|
5050
|44 | [generate randomUUID](#generate-random-uuid)|
51-
52-
53-
51+
|45 | [structuredClone](#structuredClone)|
5452

5553

5654

@@ -957,4 +955,30 @@ crypto.randomUUID() // print in console '460ff1e6-2106-4848-833d-5c5b3bfdc943'
957955
crypto.randomUUID() // print in console '9a91c014-d1b1-453a-8091-ef8b9b48b14a'
958956
959957
958+
```
959+
960+
961+
**[⬆ Back to Top](#table-of-contents)**
962+
### structuredClone
963+
964+
If you want to deep clone a value in Node.js, you no longer need to use a library or the JSON.parse(JSON.stringify(value)) hack. You can use the new global function structuredClone()
965+
966+
```javascript
967+
968+
const user = {
969+
name: "JS Snippets",
970+
address: { street: "Original Road", city: "Placeshire" },
971+
};
972+
973+
const clonedUser = structuredClone(user);
974+
975+
clonedUser.address.street = "New Road";
976+
977+
console.log("user.address.street:", user.address.street);
978+
// > Original Road
979+
980+
console.log("clonedUser.address.street:", clonedUser.address.street);
981+
// > New Road
982+
983+
960984
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy