# What does index and indexAfter on ResolvedPos exactly means?

**URL:** <https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999>\
**Category:** Show\
**Created:** [June 7, 2019, 12:53pm UTC](https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999 "2019-06-07T12:53:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monty](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@monty](https://discuss.prosemirror.net/u/monty)\
**Post date:** [June 7, 2019, 12:53pm UTC](https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999/1 "2019-06-07T12:53:37Z")

</div>

I have been trying to get my head around index() and indexAfter() functions in class ResolvedPos.

Let’s say an example, where my schema is paragraph, which has a span node, which further has text inline node.

 ![image](https://discuss.prosemirror.net/uploads/secondsite/original/1X/a1505cf474538315a787882d16d7e9e74c10872e.png)

So in this example, if i have `$from.pos = 19`, then the index return `$from.index() = 1` and indexAfter is `$from.indexAfter() = 1`.

And if i have `$from.pos = 9` then the index return `$from.index() = 0` and indexAfter is `$from.indexAfter() = 1`

So from above examples, i get confused what the index() and indexAfter() really is.

Can someone please explain what they actually do in context of the above example.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [June 7, 2019, 6:35pm UTC](https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999/2 "2019-06-07T18:35:13Z")

</div>

When called without argument, they return child indices in the position’s parent node. So for positions that fall between nodes, they’ll return the same value. For positions inside a text node, `indexAfter` will be one more than `index()`.

If you pass an argument to select an ancestor node further up the tree, `indexAfter` is always one more than `index`, because the position points into a child of that node.

---

<div class="post-metadata">

**Author:** ![monty](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@monty](https://discuss.prosemirror.net/u/monty)\
**Post date:** [June 7, 2019, 6:44pm UTC](https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999/3 "2019-06-07T18:44:13Z")

</div>

Thanks Marijn. Thats useful information. I also did some more inspection, and found out more about it.

---

<div class="post-metadata">

**Author:** ![jack](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jack](https://discuss.prosemirror.net/u/jack)\
**Post date:** [May 10, 2021, 3:36am UTC](https://discuss.prosemirror.net/t/what-does-index-and-indexafter-on-resolvedpos-exactly-means/1999/4 "2021-05-10T03:36:09Z")

</div>

I have been scratching my head to think about this until I found this explanation. I suggest we should add this to the doc of the method, because IMHO the source code is not that self-describing …
