indexWhere()
The
indexWhere()
method is used to find the index of an element in a list. It finds the index of the first occurrence of an element that satisfies the given condition.The method
indexWhere()
returns the list’s first index that matches the given condition.
Example
void main() {
var nums = [1, 2, 3, 4, 5];
var one = nums.indexWhere((element) => element % 2 == 0);
print(nums.indexWhere((element) => element > 5)); // 5
print(one);
// print(nums.indexWhere((element) => element * 2));
}
-1
1
Exited.