R
fn

get

v0.0.4tested

Safely read a deeply nested value from a collection by a dot-separated path

Example

ts
get({ user: { name: 'John' } }, 'user.name'); // 'John'
get({ items: [{ id: 1 }] }, 'items.0.id'); // 1
get({ a: 1 }, 'a.b.c'); // undefined

Signature

ts
export function get<O extends Collection, K extends string>(obj: O, path: K): Get<O, K> | undefined{ ... }

Type Parameters

Oextends Collection
Kextends string

Parameters

ParameterTypeDescription
objOThe source object or array
pathKDot-separated path, e.g. `'user.addresses.0.street'`

Returns

ExtractFromCollection<O, Path<K>> | undefinedThe resolved value, or `undefined` if any segment is missing