dart:collection
庫中ListMixin.lastIndexWhere
方法的用法介紹如下。
用法:
int lastIndexWhere(
bool test(
E element
),
[int? start]
)
override
列表中滿足提供的 test
的最後一個索引。
從索引 start
到 0 搜索列表。第一次遇到對象 o
以使 test(o)
為真時,返回 o
的索引。如果省略start
,則默認為列表的length。
final notes = <String>['do', 're', 'mi', 're'];
final first = notes.lastIndexWhere((note) => note.startsWith('r')); // 3
final second = notes.lastIndexWhere((note) => note.startsWith('r'),
2); // 1
如果未找到 element
,則返回 -1。
final notes = <String>['do', 're', 'mi', 're'];
final index = notes.lastIndexWhere((note) => note.startsWith('k'));
print(index); // -1
相關用法
- Dart ListMixin.lastIndexOf用法及代碼示例
- Dart ListMixin.lastWhere用法及代碼示例
- Dart ListMixin.last用法及代碼示例
- Dart ListMixin.expand用法及代碼示例
- Dart ListMixin.contains用法及代碼示例
- Dart ListMixin.join用法及代碼示例
- Dart ListMixin.setAll用法及代碼示例
- Dart ListMixin.where用法及代碼示例
- Dart ListMixin.toList用法及代碼示例
- Dart ListMixin.toSet用法及代碼示例
- Dart ListMixin.fillRange用法及代碼示例
- Dart ListMixin.reversed用法及代碼示例
- Dart ListMixin.take用法及代碼示例
- Dart ListMixin.insertAll用法及代碼示例
- Dart ListMixin.reduce用法及代碼示例
- Dart ListMixin.removeWhere用法及代碼示例
- Dart ListMixin.followedBy用法及代碼示例
- Dart ListMixin.getRange用法及代碼示例
- Dart ListMixin.sort用法及代碼示例
- Dart ListMixin.removeLast用法及代碼示例
- Dart ListMixin.replaceRange用法及代碼示例
- Dart ListMixin.takeWhile用法及代碼示例
- Dart ListMixin.sublist用法及代碼示例
- Dart ListMixin.forEach用法及代碼示例
- Dart ListMixin.singleWhere用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 lastIndexWhere method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。