Effective deep copy of javaScript objects
Sometimes one needs to copy a js object without any possible links to other objects, so keep it in mind:
newObj = JSON.parse(JSON.stringify(obj))
is 4 (four) times faster than
newObj = jQuery.extend(true, {}, obj)
Unfortunately it's inappropriate for objects with functions with it
Written by maikudou
Related protips
3 Responses
over 1 year ago
·
over 1 year ago
·
It seems it really depends on object size. It would be cool if jsperf had an option to map a variable to an axis (i.e. object size as 'x').
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#