Метод indexOf
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.18.5/dart-collection/ListMixin/indexOf.html