W3cubDocs

/Dart 2

elementAt method

E elementAt (int index)

Returns the indexth element.

The index must be non-negative and less than length. Index zero represents the first element (so iterable.elementAt(0) is equivalent to iterable.first).

May iterate through the elements in iteration order, ignoring the first index elements and then returning the next. Some iterables may have more a efficient way to find the element.

Implementation

E elementAt(int index) {
  if (index is! int) throw new ArgumentError.notNull("index");
  RangeError.checkNotNegative(index, "index");
  int elementIndex = 0;
  for (E element in this) {
    if (index == elementIndex) return element;
    elementIndex++;
  }
  throw new RangeError.index(index, this, "index", null, elementIndex);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-collection/IterableMixin/elementAt.html