forEachIndexed method

void forEachIndexed(
  1. void action(
    1. T element,
    2. int index
    )
)

Performs the given action on each element on iterable, providing sequential index with the element. item the element on the current iteration index the index of the current iteration

example: "a","b","c".forEachIndexed((element, index) { print("$element, $index"); }); result: a, 0 b, 1 c, 2

Implementation

void forEachIndexed(void action(T element, int index)) {
  var index = 0;
  for (var element in this) {
    action(element, index++);
  }
}