<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33" -->

---
title: 🚀 JavaScript’s Mind-Blowing `structuredClone()` – The...
description: Discussion about "🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!" on daily.dev - join the developer community
canonical: https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: 🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over! | daily.dev
og:description: Discussion about "🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!" on daily.dev - join the developer community
og:url: https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33
og:image: https://api.daily.dev/og/posts/uQqjuMq33.png
og:image:alt: 🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!

**[React Nexus 🚀](https://daily.dev/sources/reactnexus)** · [@gskkumar](https://daily.dev/gskkumar) · 74 upvotes · 22 comments

## Content

Deep cloning in JavaScript has always been a **headache**. From `JSON.parse(JSON.stringify())` breaking on functions, to libraries like `lodash.cloneDeep()`, we’ve had to rely on **workarounds**.  

But now, JavaScript has a **built-in deep cloning method**—meet **`structuredClone()`**! 😱  

---

### 🎯 **What is `structuredClone()`?**  

It’s a **native deep-cloning function** that copies objects **without breaking data types**! Unlike `JSON.stringify()`, it:  

✅ **Supports functions, Maps, Sets, Dates, TypedArrays**  
✅ **Handles circular references** 🚀  
✅ **Works natively in modern browsers & Node.js (v17+)!**  

---

### 🛠️ **Old vs New: Deep Cloning in Action**  

#### ❌ **Before (Using JSON.stringify) – Broken Cloning**  
```js
const obj = { date: new Date(), func: () => "Hello" };

const cloned = JSON.parse(JSON.stringify(obj));

console.log(cloned.date instanceof Date); // ❌ false (Broken)
console.log(cloned.func); // ❌ undefined (Functions are lost!)
```

#### ✅ **Now (Using `structuredClone()`) – Works Perfectly!**  
```js
const obj = { date: new Date(), func: () => "Hello" };

const cloned = structuredClone(obj);

console.log(cloned.date instanceof Date); // ✅ true
console.log(cloned.func); // ❌ Still not cloned (Functions aren't serializable)
```

**🚨 Note:** Functions & prototype chains aren’t cloned, but **everything else is!**  

---

### 🔥 **Why is `structuredClone()` a Game-Changer?**  

📌 **No More Manual Workarounds** – Forget third-party libraries!  
📌 **Handles Circular References** – `JSON.stringify()` crashes, but `structuredClone()` doesn’t!  
📌 **Built-In Performance Boost** – Uses optimized browser internals.  

---

### ⚡ **Bonus: Cloning Objects with Circular References**  

#### ❌ **Old Method – Throws an Error**  
```js
const obj = {};
obj.self = obj; 

JSON.parse(JSON.stringify(obj)); // ❌ ERROR: Circular structure!
```

#### ✅ **New Method – No Errors!**  
```js
const obj = {};
obj.self = obj;

const cloned = structuredClone(obj); // ✅ Works perfectly!
console.log(cloned.self === cloned); // true
```

🚀 **This makes deep cloning much safer & more reliable!**  

---

### 🎯 **Final Takeaway**  

If you’ve been **struggling with deep cloning**, JavaScript **finally** has a native solution! **`structuredClone()` is the future**, and it’s time to embrace it. 🚀  

---

### 🌍 **Let’s Connect!**  

📢 More JavaScript insights at [React Nexus](https://dly.to/mbsMLX6KLlk)  
🤝 Let’s chat on [LinkedIn](https://www.linkedin.com/in/sanjay-gopinathan)  

Tried `structuredClone()` yet? Let’s discuss your thoughts! 🔥

## Community discussion

Top comments from developers on daily.dev.

**@ibrahimbeladi** · 3 upvotes

> [Can I use `structuredClone` API?](https://caniuse.com/mdn-api_structuredclone)

**@luismmc1997** · 2 upvotes

> The only problem with the "structuredClone" function is that it doesn't clone an object's functions. Apart from that, it's very useful.
> Thanks for the content

**@knight\_03** · 1 upvotes

> Very Useful thanks for sharing

**@dhruvparmar92** · 0 upvotes

> Amazing! and Insightful

**@magicmike** · 0 upvotes

> I have been using structed clone with arrays of arrays. ChatGPT suggested in a conversation on the subject, and I have been using it ever since.

---

[View this post on daily.dev](https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33","headline":"🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!","text":"Discussion about \"🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!\" on daily.dev - join the developer community","url":"https://daily.dev/posts/javascript-s-mind-blowing-structuredclone-the-clone-wars-are-over--uqqjumq33","datePublished":"2025-03-16T14:15:53.163Z","dateModified":"2025-03-16T14:15:53.163Z","author":{"@type":"Person","name":"Sanjay Gopinathan","url":"https://daily.dev/gskkumar","image":"https://media.daily.dev/image/upload/s--6CSlcyKW--/f_auto/v1740856098/avatars/avatar_SkNrcYsA5m132VOWpNBPO?_a=BAMClqZW0","description":"React native DEV","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":390}},"image":"https://media.daily.dev/image/upload/s--SeCpB2Vm--/f_auto/v1742134553/posts/uQqjuMq33","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":74},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":22}],"comment":[{"@type":"Comment","text":"Can I use structuredClone API?","datePublished":"2025-03-26T08:58:40.717Z","url":"https://daily.dev/posts/uQqjuMq33#c-wWLXsTL8C","author":{"@type":"Person","name":"Ibrahim Al-Beladi","url":"https://daily.dev/ibrahimbeladi","image":"https://media.daily.dev/image/upload/s--IHGrdhN4--/f_auto/v1743508538/avatars/avatar_Ywv0JdPlEHb3i7RDE5rfG"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"The only problem with the “structuredClone” function is that it doesn’t clone an object’s functions. Apart from that, it’s very useful.\nThanks for the content","datePublished":"2025-03-19T20:09:21.955Z","url":"https://daily.dev/posts/uQqjuMq33#c-bVrMnf42E","author":{"@type":"Person","name":"Luís Campos","url":"https://daily.dev/luismmc1997","image":"https://avatars.githubusercontent.com/u/33434500?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Very Useful thanks for sharing","datePublished":"2025-03-18T05:21:02.959Z","url":"https://daily.dev/posts/uQqjuMq33#c-eW5BF48ip","author":{"@type":"Person","name":"Dhvani","url":"https://daily.dev/knight_03","image":"https://media.daily.dev/image/upload/s--h8XDcpiq--/f_auto/v1740025441/avatars/avatar_xWOJioMgO9tVQ6TcQUdqZ"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Amazing! and Insightful","datePublished":"2025-03-19T06:04:12.140Z","url":"https://daily.dev/posts/uQqjuMq33#c-eDWHgLkN5","author":{"@type":"Person","name":"Dhruv Parmar","url":"https://daily.dev/dhruvparmar92","image":"https://media.daily.dev/image/upload/s--jOgxSgKk--/f_auto/v1759592543/avatars/avatar_PNBsgn7cuO9oYjF05Ji50?_a=BAMAK+ZW0"}},{"@type":"Comment","text":"I have been using structed clone with arrays of arrays. ChatGPT suggested in a conversation on the subject, and I have been using it ever since.","datePublished":"2025-03-23T02:52:00.846Z","url":"https://daily.dev/posts/uQqjuMq33#c-afOn4T7wD","author":{"@type":"Person","name":"Michael Lindo","url":"https://daily.dev/magicmike","image":"https://lh3.googleusercontent.com/a-/AAuE7mBvxHOCZ7KGMgPAAjYqz9c6bOddZAfbbqbLOG8O=s100"}}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/reactnexus","name":"React Nexus 🚀"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"React Nexus 🚀","item":"https://daily.dev/squads/reactnexus"},{"@type":"ListItem","position":3,"name":"🚀 JavaScript’s Mind-Blowing `structuredClone()` – The Clone Wars Are Over!"}]}
```

