By default, only existing array indexes can be updated. Use the allowShapeChange parameter
to allow setting arbitrary indexes.
// Throws because array index 3 is undefined updateByPath([ `a`, `b`, `c` ], `3`, `d`);
// With allowShapeChange flag updateByPath([ `a`, `b`, `c` ], `3`, `d`, true); // Returns: [ `a`, `b`, `c`, `d` ]
Throws an error if:
path cannot be resolved (eg. position.z in the above example)
value applied to target results in the object having a different shape (eg missing a field, field
changing type, or array index out of bounds). Use allowShapeChange to suppress this error.
Path is undefined or not a string
Target is undefined/null
updateByPath<V>(target, path, value, allowShapeChange?): V
Returns a copy of
target
object with a specified path changed tovalue
.Paths can also be array indexes:
By default, only existing array indexes can be updated. Use the
allowShapeChange
parameter to allow setting arbitrary indexes.Throws an error if:
path
cannot be resolved (eg.position.z
in the above example)value
applied totarget
results in the object having a different shape (eg missing a field, field changing type, or array index out of bounds). UseallowShapeChange
to suppress this error.