Use the special property `$index` to get the current index while iterating.