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:
done field of its corresponding array item. When the user checks row 2, todos.2.done gets updated.
Nested Loops
When you nestForEach 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: