Метод indexOf
int indexOf(Возвращает первый индекс element в этом списке.
Ищет в списке от индекса start до конца списка. В первый раз, когда встречается объект o, так что o == element, возвращается индекс o.
List<String> notes = ['do', 're', 'mi', 're'];
notes.indexOf('re'); // 1
notes.indexOf('re', 2); // 3
Возвращает -1, если element не найден.
notes.indexOf('fa'); // -1
Исходный код
int indexOf(Object element, [int startIndex = 0]) {
if (startIndex >= this.length) {
return -1;
}
if (startIndex < 0) {
startIndex = 0;
}
for (int i = startIndex; i < this.length; i++) {
if (this[i] == element) {
return i;
}
}
return -1;
}
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-collection/ListMixin/indexOf.html