The _.set()
method in Lodash is used to set the value at a specific path of the object.
_.set(object, path, value)
This method accepts the following parameters:
object
: This is the object where the given value needs to be set.path
: This is the path at which the given value needs to be set.value
: This is the value to be set.This method modifies the given object and returns the modified object.
Let’s look at an example of the _.set()
method in the code snippet below:
In the HTML tab:
lodash
script.In the JavaScript tab:
collegeEducation
that is the value to be set.path
where the value is set._.set()
method and pass the object
, path
and value
as parameters. And we print the output on the console.The _.set()
method sets the given value at the specified path and returns the modified object, which is printed to the console.