Skip to content
Advertisement

Lodash _.set only if object exists

I am looking to set inner properties of an object only if they already exist. Lodash _.set will create the whole hierarchy if it does not exist.

Is there an easy way to do this ? (Without and if statement ?)

Snippet below:

JavaScript
JavaScript

Advertisement

Answer

The answer from Kalaiselvan A below put me on the way but this is not quite what I was looking for.

Using the same idea but improving the ternary gives me the following solution which I am happy with.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement