Skip to main content
Results for deep clone object javascript
Search options not deleted
500 results
5157 votes
67 answers
3.1m views

What is the most efficient way to deep clone an object in JavaScript?

What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox. …
2501 votes

What is the most efficient way to deep clone an object in JavaScript?

jQuery.extend is pretty fast when the deep flag is set to false (shallow clone). … If you know the structure of the objects you are trying to clone or can avoid deep nested arrays you can write a simple for (var i in obj) loop to clone your object while checking hasOwnProperty and it …
641 votes
32 answers
667k views

How do you clone an array of objects in JavaScript?

When I first came up with this problem I just thought of something like var clonedNodesArray = nodesArray.clone() would exist and searched for information on how to clone objects in JavaScript. … Then I tried var clonedNodesArray = jQuery.extend(true, {}, nodesArray); which deep copies an Object, but I got "too much recursion" and "control stack overflow" messages from both Firebug and Opera Dragonfly …
wallyqs's user avatar
  • 7,896
188 votes
27 answers
245k views

How to Deep clone in JavaScript

How do you deep clone a JavaScript object? … What is the most elegant or efficient way to create a deep clone. We do care about edge cases like cloning array's. Not breaking prototype chains, dealing with self reference. …
Raynos's user avatar
  • 170k
22 votes
5 answers
22k views

Javascript Deep Clone Object with Circular References

This function can deep clone an object without any circular references- it works. function deepClone( obj ) { if( ! …
Lucien's user avatar
  • 926
2092 votes
Accepted

How do I correctly clone a JavaScript object?

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. … For example, a Date object stores its data as a hidden member: function clone(obj) { if (null == obj || "object" ! …
A. Levy's user avatar
  • 31k
0 votes
1 answer
2k views

How to deep clone object with functions in Javascript? [duplicate]

I search for a bit, and found a few ways: structuredClone() - Error: Function object could not be cloned. {...levels[leve]} - Doesn't not deep copy Object.assign({},levels[level]) - Doesn't not deep copy … JSON.parse(JSON.stringify(levels[campaing][id])) Doesn't copy functions How to Deep clone in javascript - does not copy functions Looks like my problem is that my levels[level] is object with object, …
Dzhake's user avatar
  • 1
0 votes
0 answers
27 views

How to Implement Deep Cloning of Objects in JavaScript? [duplicate]

I'm facing a challenge in JavaScript where I need to create a deep clone of an object. The object can have nested objects, arrays, and different types of properties. … "] }; I want to create a deep clone of this object so that changes to the nested objects or arrays in the cloned object do not affect the original object. …
yuekandy's user avatar
3 votes
2 answers
3k views

Deep Cloning an object on the client side (GWT + Javascript) ?

I know of a Deep Cloning library in Java, which I use in my server side code. However, right now I need to "deep clone" an object on the client side code. … I believe there's a Javascript framework that does this thing which is YUI3, however I am not sure how to use this with my GWT code. …
quarks's user avatar
  • 35.7k
0 votes
0 answers
46 views

Deep clone Object does not run function - javascript

I am trying to clone an Object that is frozen with npm deep-freeze, but the function will not run itself again. … I have tried to run the if(typeof === "object"), followed by Object.assign, but this gives me the typeError: Cannot assign to read only property function updateTree(tree, id, values) { const treeData …
Johan Jensen's user avatar
1 vote
2 answers
788 views

How do I deep clone XMLDocument Object in Javascript?

I'm creating a tool that parses XML file into XMLDocument object. … The question is - how to make deep clone of parsed xml object? Thanks! …
Vadym Shashkov's user avatar
1 vote
0 answers
75 views

Deep clone object in Javascript except Object.assign [duplicate]

Object.assign doesn't deep copy an object. considering following code it should print 0 0 0 1 but it is printing 0 0 1 1. …
Rashmin Javiya's user avatar
0 votes
2 answers
460 views

Which JavaScript objects don't Deep Clone by default?

, not part of JavaScript. … What objects require deep-cloning and why? …
5 votes
1 answer
1k views

Is there a language-level way to deep clone a JavaScript object?

Is there a language-level way to deep clone a JavaScript object that is supported by main browsers (desktop and mobile)? I've seen that eval(uneval(o)); is non-standard. … Just copy the bytes from the object to somewhere else in the RAM. Anything done above this looks like an inefficiency to me. …
yılmaz's user avatar
  • 461
0 votes
1 answer
439 views

What is a good way to implement a deep clone function for nested objects in JavaScript? [duplicate]

"I am looking for a reliable approach to implement a deep clone function in JavaScript that can create a complete copy of an object, including all nested properties and arrays. … Could someone suggest an effective solution to implement a deep clone function that properly handles nested objects in JavaScript? Your assistance would be greatly appreciated. Thank you!" …
Haitham6373's user avatar
  • 1,309

1
2 3 4 5
33
15 30 50 per page