F

findInTree

Finds the first node in an object graph a predicate matches, depth-first from the root. Cycle-safe.

function findInTree<T = any>(root: any, predicate: TreePredicate, options?: TreeSearchOptions): T | undefined

Parameters

NameTypeDescription
rootany

The node to start from; it is tested too.

predicateTreePredicate

Tests each non-nullish node.

options?TreeSearchOptions

Which keys to descend into or skip, and how deep.

Returns

T | undefined

The first match, or undefined when none matches.