Sets the value at path of object. If a portion of path doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties. Use setWith to customize path creation.
path
object
setWith
Note: This method mutates object.
The object to modify.
The path of the property to set.
The value to set.
Returns object.
3.7.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)// => 4set(object, ['x', '0', 'y', 'z'], 5)console.log(object.x[0].y.z)// => 5 Copy
const object = { 'a': [{ 'b': { 'c': 3 } }] }set(object, 'a[0].b.c', 4)console.log(object.a[0].b.c)// => 4set(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
.