Logo

Programming-Idioms

History of Idiom 7 > diff from v100 to v101

Edit summary for version 101 by programming-idioms.org:
[Dart] +DocURL

Version 100

2020-11-22, 00:33:27

Version 101

2020-12-14, 22:43:32

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
items.asMap().forEach((i, value) {
  print('index=$i, value=$value');
});
Code
items.asMap().forEach((i, value) {
  print('index=$i, value=$value');
});
Comments bubble
An alternative, but not really idiomatic.
Comments bubble
An alternative, but not really idiomatic.
Doc URL
https://api.dart.dev/stable/2.10.4/dart-core/List/asMap.html
Demo URL
https://dartpad.dev/0337a175b949727eb6ee32900d7e35fa
Demo URL
https://dartpad.dev/0337a175b949727eb6ee32900d7e35fa