indexOf method

int indexOf(
  1. T element, [
  2. int start = 0
])

Returns the index of the first element in the list.

Searches the list from index start to the end of the list. The first time an object o is encountered so that o == element, the index of o is returned.

If start is not provided, this method searches from the start of the list.

final IList<String> notes = ['do', 're', 'mi', 're'].lock;
notes.indexOf('re');    // 1
notes.indexOf('re', 2); // 3

Returns -1 if element is not found.

notes.indexOf('fa');    // -1

Implementation

int indexOf(T element, [int start = 0]) {
  _count();
  var _length = length;
  if (start < 0 || start >= _length)
    throw ArgumentError.value(start, "index", "Index out of range");
  for (int i = start; i <= _length - 1; i++) if (this[i] == element) return i;
  return -1;
}