Skip to main content
Module

x/rimbu/deep/deep.ts>getAt

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function getAt
import { getAt } from "https://deno.land/x/rimbu@0.14.0/deep/deep.ts";

Returns the value resulting from selecting the given path in the given source object. It supports optional chaining for nullable values or values that may be undefined, and also for accessing objects inside an array. There is currently no support for forcing non-null (the ! operator).

Examples

Example 1

const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
Deep.getAt(value, 'a.b');
// => { c: 5 }
Deep.getAt(value, 'a.b.c');
// => [{ d: 5 }, { d: 5 }]
Deep.getAt(value, 'a.b.c[1]');
// => { d: 6 }
Deep.getAt(value, 'a.b.c[1]?.d');
// => 6

Type Parameters

T
P extends Path.Get<T>

Parameters

source: T
  • the object to select in
path: P
  • the path into the object

Returns

Path.Result<T, P>