Dart Iterable Skip() & SkipWhile()

Dart Iterable Skip() & SkipWhile()

Skip()

  • This method skips the first elements from the iterable and returns a new iterable that starts after those elements.

SkipWhile()

  • This method skips elements while a condition is true, and once the condition becomes false for an element, it stops skipping and returns the rest of the elements.

Example

void main() {
  var number = [1, 2, 3, 4, 5];
  var skip = number.skip(2);
  print(skip);

  var number1 = [1, 2, 3, 4, 5, 23, 44, 55, 66];
  var skips = number1.skipWhile((number1) => number1 < 3);
  print(skips); // Skip all elements in the list because
}

Output

(3, 4, 5)
(3, 4, 5, 23, 44, 55, 66)

Exited.