gpt4 book ai didi

dart - 在 Dart 中枚举或映射具有索引和值的列表

转载 作者:IT老高 更新时间:2023-10-28 12:29:14 29 4
gpt4 key购买 nike

在 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);

希望这会有所帮助!

关于dart - 在 Dart 中枚举或映射具有索引和值的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54898767/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com