The object to modify.
The path of the property to set.
The value to set.
Returns object
.
5.3.0
[[has]],[[hasIn]],[[get]],[[unset]]
const object = { 'a': [{ 'b': { 'c': 3 } }] }
set(object, 'a[0].b.c', 4)
console.log(object.a[0].b.c)
// => 4
set(object, ['x', '0', 'y', 'z'], 5)
console.log(object.x[0].y.z)
// => 5
Sets the value at
path
ofobject
. If a portion ofpath
doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties. UsesetWith
to customizepath
creation.Note: This method mutates
object
.