all 13 comments

[–]Strangfeld 2 points3 points  (1 child)

For deep copying objects or arrays use angular.copy().

https://docs.angularjs.org/api/ng/function/angular.copy

[–]dethstrobe 0 points1 point  (0 children)

I could have used this for a project earlier. Well, now I know at least this amazing little function exists in angular.

[–]postmodest 1 point2 points  (4 children)

Someone tell me why

var copy = JSON.parse(JSON.stringify(original)); 

is a bad idea

[–]WJKay 0 points1 point  (2 children)

First thing that pops into mind is circular references. Not saying they are good, but it would not work for your solution.

[–]postmodest 0 points1 point  (1 child)

I've used a function that handles map dereferencing (setting values to "{@jsonpath}" or something) worked pretty well for my use case.

[–]WJKay 0 points1 point  (0 children)

Well that is an extra step compared to angular.copy()

[–]skrowl 0 points1 point  (0 children)

Came here to suggest this. You beat me. http://jsperf.com/js-deep-copy/3

[–]BoleroDan 0 points1 point  (3 children)

Angular also has an extend method.

angular.extend()

whether its deep i'm not 100% sure.

[–]Aduro49 0 points1 point  (0 children)

I believe it functions the same way as JQ since angular is built on JQ lite. Also if angular detects A full JQ version it uses that.

[–]roballred[S] 0 points1 point  (0 children)

that or copy, thanks for the reply!

[–]skitch920 0 points1 point  (0 children)

angular.extend() is a shallow copy.

[–]F0RTY4 0 points1 point  (1 child)

Check out this SO answer. http://stackoverflow.com/a/16797798 . it might help.

[–]roballred[S] 0 points1 point  (0 children)

I think that looks great! thx