forEachIndexed method

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

Iterates through the iterable with both index and element.

Example:

[1, 2].forEachIndexed((index, element) => print('$index: $element'));

Implementation

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