Skip to content

getObjectFromDottedString ​

Function that, given a path, a value and an optional object, returns an object with as many properties as there are in the path, assigning the value passed to the last one specified. See demo

Types ​

GetObjectFromDottedStringProps ​

  • @template T - The type of the value to set at the resolved path.
  • @template E - The object type to build or update.

Parameters accepted by getObjectFromDottedString.

PropertyTypeRequiredDescription
pathstring✓A dot-separated path string describing where to set the value within the object (e.g. "user.address.city"). Each segment corresponds to a nested property key.
valueT✓The value to assign at the location described by path.
objectEAn optional existing object to update. When provided, the value is set within a deep clone of this object. When omitted, a new object is built from scratch following the structure described by path.

Released under the MIT License.