Skip to main content

Function: findParentPath()

function findParentPath<T>(
child,
predicate,
maxDepth?
):
| FoundParentPath<T>
| undefined;

Iterates through all the parents (from the nearest until the root) until one of them matches the given predicate. If the predicate is matched it will return the found node plus the path to get from the parent to the child. If none is found it will return undefined.

Type Parameters​

Type ParameterDefault typeDescription
T extends objectanyParent object type.

Parameters​

ParameterTypeDefault valueDescription
childobjectundefinedTarget object.
predicate(parentNode) => booleanundefinedFunction that will be run for every parent of the target object, from immediate parent to the root.
maxDepthnumber0Max depth, or 0 for infinite.

Returns​

| FoundParentPath<T> | undefined