FlutterUnit icon indicating copy to clipboard operation
FlutterUnit copied to clipboard

+0016 遍历List时如何获取元素索引值 index

Open toly1994328 opened this issue 4 years ago • 2 comments

toly1994328 avatar Jun 05 '20 04:06 toly1994328

  • 使用List.asMap遍历
void t2() {
  List a = ['a','b','c','d'];
  a.asMap().forEach((index, value)=>print('--$index-----$value--------'));
}

--0-----a--------
--1-----b--------
--2-----c--------
--3-----d--------

toly1994328 avatar Jun 05 '20 04:06 toly1994328

@toly1994328 我有个疑问 将数组转成字典 字典特点是无序在循环遍历的时候。在Dart中这样用会不会出现问题?

josercc avatar Oct 08 '22 11:10 josercc