---
title: "findNearestAncestor"
description: "Finds the nearest traversable ancestor with a matching [key]."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun DelegatableNode.findNearestAncestor(key: Any?): TraversableNode?
```


Finds the nearest traversable ancestor with a matching `key`.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun <T> T.findNearestAncestor(): T? where T : TraversableNode
```


Finds the nearest ancestor of the same class and key.



