Friday, 17 May 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...