apps-script-utils 2.1.1 Help

setPath

function setPath<T extends object>( target: T, path: string | Array<string | number>, value: unknown ): T;

Missing links are created along the way: a numeric segment makes an array, a string segment an object. setPath({}, ["rows", 0, "id"], 7) therefore produces { rows: [{ id: 7 }] }.

The target is modified in place and returned, so the call composes but does not copy.

Parameters

Parameter

Type

Description

target

T

The object to write into. It is modified.

path

string \| Array<string \| number>

A dotted string, or an array of keys and indices.

value

unknown

The value to write.

Returns

T — the same object, now carrying the value.

Throws

Exception

Condition

IllegalArgumentException

the target is not an object, or the path is empty.

Examples

Writing

setPath({}, "a.b", 1); // => { "a": { "b": 1 } } setPath({}, ["rows", 0, "id"], 7); // => { "rows": [{ "id": 7 }] }

See also

Source

src/lang/object/setPath.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.