Clone an object

Clone an object in JavaScript — with three ready prompts, from the immediate task to the lasting pattern.

3prompt heights
Open it in the interactive atlas →

3 ready prompts

Written for the moment this actually comes up.

Improve — make it easier to accept

+
Before I hand this to the reviewer, make the clone simple to audit: produce a deep clone function…
Before I hand this to the reviewer, make the clone simple to audit: produce a deep clone function named deepClone that handles nested plain objects and arrays, avoids copying functions, and returns a new object for the example above. Keep it minimal and add one short comment about limitations.

Decide — diagnose the stuck moment

+
I copied an object with const copy = original; made changes to copy.meta.retries and saw original…

I mutated the original while thinking I had cloned it

I copied an object with const copy = original; made changes to copy.meta.retries and saw original change too. I don't know whether to use spread, Object.assign, or JSON methods for a reliable clone here. Which approach caused this, and which cloning method should I use for nested plain objects without functions?

Become — change the pattern

+
On many tickets we see bugs caused by shallow copies: someone uses the spread operator and later…

We repeatedly lose time fixing accidental shared references

On many tickets we see bugs caused by shallow copies: someone uses the spread operator and later mutates a nested field, creating production defects. I want a simple team habit or utility that prevents this class of bug without forcing a heavyweight library. What should we adopt as the default cloning practice?

Next to this one

Other programming language work people do in JavaScript.

Every task here came from the work, not from a feature list — which is why the prompts name what you want done and never the button that does it. The tool changes; the work does not.
Copyright © LLOS.ai · 2026 — original pedagogy, voice, and design — all rights reserved.

The rest of the map

Same library, five ways in.