Created
July 8, 2018 13:12
-
-
Save Blasanka/bb0a2cd7623635bf9da967d0a25e94fd to your computer and use it in GitHub Desktop.
replace items in a list or update items in a list in dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The easy way: | |
void main() { | |
var collection=[0, 1, 2]; | |
for(int i = 0; i < collection.length; i++) { | |
collection[i] += 1; | |
} | |
print(collection); | |
} | |
//Using replaceRange: | |
void main() { | |
var collection=[0, 1, 2]; | |
var temp = collection.map((c) => c+1).toList(); | |
collection.replaceRange(0, collection.length, temp); | |
print(collection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment