|
48 | 48 | |42|[Native text to speech JS](#Native-text-to-speech-JS)|
|
49 | 49 | |43|[toFixed](#toFixed)|
|
50 | 50 | |44|[generate randomUUID](#generate-random-uuid)|
|
51 |
| - |
52 |
| - |
53 |
| - |
| 51 | +|45|[structuredClone](#structuredClone)| |
54 | 52 |
|
55 | 53 |
|
56 | 54 |
|
@@ -957,4 +955,30 @@ crypto.randomUUID() // print in console '460ff1e6-2106-4848-833d-5c5b3bfdc943'
|
957 | 955 | crypto.randomUUID() // print in console '9a91c014-d1b1-453a-8091-ef8b9b48b14a'
|
958 | 956 |
|
959 | 957 |
|
| 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 | +
|
960 | 984 | ```
|