---
title: "The Best Way to Deep Copy an Object in JavaScript"
url: https://daily.dev/posts/the-best-way-to-deep-copy-an-object-in-javascript-tatlq92k4
source_url: https://code.tutsplus.com/articles/the-best-way-to-deep-copy-an-object-in-javascript--cms-39655
type: article
source: "Tuts+"
published: 2022-03-08T00:40:00.217Z
updated: 2022-03-08T00:40:00.217Z
tags: ["webdev", "javascript"]
reading_time: 5
upvotes: 10
comments: 3
language: 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.

# The Best Way to Deep Copy an Object in JavaScript

**[Tuts\+](https://daily.dev/sources/tuts_plus)** · 5 min read · 10 upvotes · 3 comments

## Summary

In a reassignment operation involving primitive data types such as strings, numbers and booleans, the original variable is copied by JavaScript. With non-primitive data types like arrays and objects, only a reference to the values is passed. This is also known as shallow copying. If we instead want to copy an object so that we can modify it without affecting the original object, we need to make a deep copy.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://code.tutsplus.com/articles/the-best-way-to-deep-copy-an-object-in-javascript--cms-39655>

## Community discussion

Top comments from developers on daily.dev.

**@sshanzel** · 1 upvotes

> There is built-in support for [deep cloning](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) an object. I think it was introduced recently, looking at the last update from the docs itself.

**@jmezzacappa** · 0 upvotes

> I implemented a "lazy" copy thing a while back using proxies. It's kinda similar to what Immer does.
> ...Tbh, I'd probably just recommend Immer now if something like that is needed.

**@jeromew** · 0 upvotes

> Incredible article, thanks!

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/the-best-way-to-deep-copy-an-object-in-javascript-tatlq92k4)
