Enumerate or map through a list with index and value in Dart


In dart there any equivalent to the common:

enumerate(List) -> Iterator((index, value) => f)
List.enumerate()  -> Iterator((index, value) => f)
List.map() -> Iterator((index, value) => f)

It seems that this is the easiest way but it still seems strange that this functionality wouldn’t exist.

Iterable<int>.generate(list.length).forEach( (index) => {
  newList.add(list[index], index)


There is a asMap method which converts the list to a map where the keys are the index and values are the element at index. Please take a look at the docs here.


List _sample = ['a','b','c'];
_sample.asMap().forEach((index, value) => f);

Hope this helps!

Answered By – Hemanth Raj

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *