set
set<
T>(params):Record<string,unknown>
Defined in: objects/set/index.ts:42
Sets a nested value on an object using dot-notation path. Non-mutating: returns a new object with only the nodes on the path cloned.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”params
Section titled “params”SetParams<T>
The parameters object
Returns
Section titled “Returns”Record<string, unknown>
A new object with value set at path
Example
Section titled “Example”set({ obj: { a: { b: 1 } }, path: "a.b", value: 2 });// => { a: { b: 2 } }
set({ obj: {}, path: "items.0.name", value: "x" });// => { items: [{ name: "x" }] }
set({ obj: {}, path: "items.0.name", value: "x", objectify: true });// => { items: { "0": { name: "x" } } }Keywords
Section titled “Keywords”write nested, dot notation, deep set, property path, immutable set, lodash set
Throws
Section titled “Throws”Error if obj is not an object
Throws
Section titled “Throws”Error if path is not a string
Throws
Section titled “Throws”Error if path is empty