Skip to main content
INDEX is a reactive reference to $index — the zero-based position of the current item in a ForEach loop. It’s essential for targeting specific items in state arrays.

Targeting Array Items

INDEX is the key to modifying specific items in a list. Without it, you’d have no way to know which row the user clicked:
This binds each checkbox to the done field of its corresponding array item. When the user checks row 2, todos.2.done gets updated.

Nested Loops

When you nest ForEach loops, the inner loop shadows $index. Capture the outer index with let before entering the inner loop:

Arithmetic

INDEX supports operators like any Rx reference. Show 1-based numbering with INDEX + 1, or use it in comparisons:

Import