by @kodeazy
flutter How to modify values list based on index in a dart file?
- In this blog we will discuss on how to update the values of
List
based on index in dart file. -
Lets suppose we have an list of integers as below
List<int> exampleArray = [1, 2, 3];
-
To replace the
Third element
below is the syntax.exampleArray[2] = 9;
- As the
index
starts from0
we specify theindex
as2
to get the3
rd element. -
Below is the example program of modifying the
List
.void main() { List<int> exampleArray = [1, 2, 3]; exampleArray[2] = 9; print(exampleArray); }
Output:
[1, 2, 9]