Dart Iterable firstWhere()

Dart Iterable firstWhere()

·

1 min read

firstWhere():

  • The first element that satisfies the given predicate test.

  • Iterates through elements and returns the first to satisfy test.

Example:

void main() {
  Iterable<int> item = [1, 2, 3, 4, 6, 4, 6, 7];
  int first = item.firstWhere((item) => item % 2 == 0);
  print(first);
  int second = item.firstWhere((element) => element % 2 != 0);
  print(second); // Output: 4
}
2
1

Exited.