The setWith
function from lodash allows us to set the value of the property in the target object using a customizer function. The customizer function provides the ability to modify the value being set, based on the current key and the parent object. The setWith
function has the following signature:
index.tsx43 chars2 lines
Here, object
is the target object, path
is the path at which to set the value, value
is the value to set, and customizer
is the function used to customize the setting of the value.
Here is an example usage of the setWith
function:
index.tsx319 chars12 lines
In this example, we modified the value
being set by doubling it before setting it in the parentObject
. Therefore, the output of console.log(object.a[0].b.c)
is 8
instead of the original 4
gistlibby LogSnag