在 dart 中有任何等价于 common:
enumerate(List) -> Iterator((index, value) => f)
or
List.enumerate() -> Iterator((index, value) => f)
or
List.map() -> Iterator((index, value) => f)
这似乎是最简单的方法,但这个功能不存在似乎仍然很奇怪。
Iterable<int>.generate(list.length).forEach( (index) => {
newList.add(list[index], index)
});
最佳答案
有一个 asMap
方法可以将列表转换为映射,其中键是索引,值是索引处的元素。请查看文档 here .
例子:
List _sample = ['a','b','c'];
_sample.asMap().forEach((index, value) => f);
希望这会有所帮助!
https://stackoverflow.com/questions/54898767/