April 2020
Intermediate to advanced
490 pages
11h 7m
English
The map() method transforms each element in a list and returns the result of the transformation in a new list. Let's see this method in action by editing our code:
void main() { String mySongs = sing(); print (mySongs); }String sing() { var songs = List<String>(); songs.add('We will Rock You'); songs.add('One'); songs.add('Sultans of Swing'); var capitalSongs = songs.map((song)=> song.toUpperCase()); return capitalSongs.toString(); }
The result of this code is that the songs are now printed in uppercase, but the interesting part of the code is the following line:
var capitalSongs = songs.map((song)=> song.toUpperCase());
Here, you can see the map() method of a list in action. For each element of the list, in this case a song, the ...
Read now
Unlock full access