List<String> subjects = ["math", "physics", "chemistry"];
subjects.insert(0, "english");
print(subjects);
In the above code, we have a list of named subjects that contains subject names. We want to add a new subject name to the first position of this dart list. We are using the below code syntax to insert the item at the beginning of the list.
subjects.insert(0, "english");
//Syntax
List.insert(index, item)
List<String> cars = ["Volvo", "TATA", "Hyundai"];
cars = ["Audi", ...cars];
print(cars);
// -> [Audi, Volvo, TATA, Hyundai]
List<String> _fruits = ["Apple", "Banana", "Orange"];
_fruits = ["Papaya", for (String fruit in _fruits) fruit];
print(_fruits);
// -> [Papaya, Apple, Banana, Orange]
0 Comments