Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/deep/internal.ts>Deep.getAt

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

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

Parameters

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