findIndex method
find the first element index that satisfies the given predicate test.
Iterates through elements and returns the first element index to satisfy test.
Example:
final numbers = <int>[1, 2, 3, 5, 6, 7];
int result = numbers.findIndex((element) => element < 5); // 0
int result = numbers.findIndex((element) => element > 5); // 4
int result = numbers.findIndex((element) => element > 10); // -1
Stops iterating on the first matching element.
Implementation
int findIndex(bool Function(E element) test) {
int index = -1;
for (E element in this) {
index++;
if (test(element)) return index;
}
return 0;
}