dart:core 库中List.lastIndexWhere 方法的用法介绍如下。
用法:
int lastIndexWhere(
bool test(
E element
),
[int? start]
)
列表中满足提供的 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 List.lastIndexOf用法及代码示例
- Dart List.last用法及代码示例
- Dart List.length用法及代码示例
- Dart List.first用法及代码示例
- Dart List.sort用法及代码示例
- Dart List.fillRange用法及代码示例
- Dart List.addAll用法及代码示例
- Dart List.indexOf用法及代码示例
- Dart List.removeWhere用法及代码示例
- Dart List.reversed用法及代码示例
- Dart List.removeRange用法及代码示例
- Dart List.unmodifiable用法及代码示例
- Dart List.clear用法及代码示例
- Dart List.from用法及代码示例
- Dart List.removeAt用法及代码示例
- Dart List.retainWhere用法及代码示例
- Dart List.shuffle用法及代码示例
- Dart List.removeLast用法及代码示例
- Dart List.setAll用法及代码示例
- Dart List.filled用法及代码示例
- Dart List.empty用法及代码示例
- Dart List.of用法及代码示例
- Dart List.setRange用法及代码示例
- Dart List.replaceRange用法及代码示例
- Dart List.remove用法及代码示例
注:本文由纯净天空筛选整理自dart.dev大神的英文原创作品 lastIndexWhere method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
