Метод lastIndexOf
override
Последний индекс element в этом списке.
Выполняет поиск в списке в обратном порядке, от индекса start до 0.
При первом обнаружении объекта o, такого что o == element, возвращается индекс o.
final notes = <String>['do', 're', 'mi', 're'];
const startIndex = 2;
final index = notes.lastIndexOf('re', startIndex); // 1 Если start не указан, этот метод выполняет поиск с конца списка.
final notes = <String>['do', 're', 'mi', 're'];
final index = notes.lastIndexOf('re'); // 3 Возвращает -1, если element не найден.
final notes = <String>['do', 're', 'mi', 're'];
final index = notes.lastIndexOf('fa'); // -1 Реализация
int lastIndexOf(Object? element, [int? start]) {
if (start == null || start >= this.length) start = this.length - 1;
// TODO(38493): The previous line should promote.
if (start == null) throw "!";
for (int i = start; i >= 0; 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/lastIndexOf.html