indexOf method
override
Первый индекс element в этом списке.
Выполняет поиск в списке начиная с индекса start и до конца списка. При первой встрече объекта o, для которого выполняется условие o == element, возвращается индекс o.
final notes = <String>['do', 're', 'mi', 're'];
print(notes.indexOf('re')); // 1
final indexWithStart = notes.indexOf('re', 2); // 3 Возвращает -1, если element не найден.
final notes = <String>['do', 're', 'mi', 're'];
final index = notes.indexOf('fa'); // -1 Реализация
int indexOf(Object? element, [int start = 0]) {
if (start < 0) start = 0;
for (int i = start; i < this.length; i++) {
if (this[i] == element) return i;
}
return -1;
}
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.19.6/dart-collection/ListMixin/indexOf.html