setNestedProperty()
Function: setNestedProperty()
Section titled “Function: setNestedProperty()”function setNestedProperty( obj, field, value): void;Sets or deletes a nested property in an object using PHP-style bracket notation. If value is null or undefined, deletes the property and cleans up empty parents.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
obj | any | The object to modify. |
field | string | The field path in PHP-style bracket notation (e.g. ‘a[b][c]’). |
value | any | The value to set. If null or undefined, the property is deleted. |
Returns
Section titled “Returns”void
Example
Section titled “Example”setNestedProperty(obj, 'a[b][c]', 123) // obj.a.b.c = 123setNestedProperty(obj, 'a[b][c]', null) // deletes obj.a.b.c