Friday, May 17, 2019

javascript - How to clone js object?











How to clone js object with out reference like these:



{ ID: _docEl,
Index: next,
DocName: _el
}


Any ideas?



Answer



You'll have to iterate over the object and make copies of all its properties.



And then if any of its properties are also objects, assuming you want to clone those too, you'll have to recurse into them.



There's various methods for doing this here:
What is the most efficient way to clone a JavaScript object?


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...