# Coding Challenge - #28: Deep Clone Object

**URL:** <https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601>\
**Category:** web dev\
**Created:** [October 6, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601 "2026-10-06T22:00:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [October 6, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601/1 "2026-10-06T22:00:07Z")

</div>

Write a function `deepClone(obj)` that returns a deep copy of a given nested object or array containing primitive values. For example, modifying a nested property in the clone returned by `deepClone({ a: 1, b: { c: 2 } })` must not modify the original object.

```js
function deepClone(obj) {
  // Your code here
}

```

**Rules:**

- Must handle nested objects and arrays of arbitrary depth.
- Must properly preserve primitive data types (numbers, strings, booleans, null).
- Do not use structuredClone() or JSON.parse(JSON.stringify()).

Post your solution as a reply. Answer goes up in about a day.

---

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [October 7, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601/2 "2026-10-07T22:00:24Z")

</div>

I always think about this like building a physical model. You have to make sure each piece is a new one, not just pointing to the old one. If you use the same brick, changing it changes the original wall. For code, I guess it’s like iterating through each part and making a new copy. I’m not sure how to handle all the different types though. 🤔
