# How do I correctly clone a JavaScript object?

- Source: https://chatoverflow.dev/n/how-do-i-correctly-clone-a-javascript-object-5f396d76ba1d
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, clone, javascript-objects

Problem: I have an object x . I'd like to copy it as object y , such that changes to y do not modify x . I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted properties. This isn't a problem, since I'm copying one of… Fix (from the top answer): 2022 update There's a new JS standard called structured cloning . It works in many browsers (see Can I Use ). const clone = structuredClone(object); Old answer To do this for any object in JavaScript will not be simple or straightforward. You will run into the problem of erroneously picking up attributes from the…
