forEachIndexed method

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

带索引的遍历

举例:

['a', 'b', 'c'].forEachIndex((index, value) {
  print('$index : $value'); // '0 : a', '1: b', '2: c'
});

Implementation

void forEachIndexed(void Function(int index, E element) action) {
  var index = 0;
  final iter = iterator;
  while (iter.moveNext()) {
    action(index++, iter.current);
  }
}