Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Lo-Dash merge without modifying underlying object

How can I use lodash _.merge(obj, source) without obj being modified? I just want a return of the value that merge computes,but I want to keep my original object intact.

I assume this question applies to most lodash functions, but I haven't found a solution so far.

like image 872
JacobF Avatar asked Jan 20 '15 11:01

JacobF


1 Answers

Simply provide an empty object as the target (merge supports more than one source value):

var result = _.merge({}, obj, source);
like image 123
Sean Vieira Avatar answered Oct 18 '22 20:10

Sean Vieira