New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
I copy a settings object with the spread operator, change one nested field on the copy, and the original changes too.
What you'll have at the end
A clone function where editing the copy's nested fields never changes the original object
You need
a plain object your interface already copies before letting someone edit it, with at least one nested object or array inside, like a widget's style settings or a list of records
Not covered
keeping a clone usable after it's transferred to a Web Worker instead of copied, and supporting a browser too old to have the clone function this recipe relies on
Checked 21 Aug 2026
Part of the JavaScript cookbook