The removeAt()
method removes the value at the specified index in the list.
The syntax of the function is as follows:
List_name.removeAt(int index);
Note:
List_name
is the name of the list.
Index
(required): The index of the element that should be removed from the list.The removeAt()
method returns the element that is removed from the list.
The following code demonstrates the use of list.removeAt()
in Dart.
void main() {//Creating listvar myList = [2,6, 'Apple', 'Pen', 'three', 'Mango', 'five'];// display resultprint('The list before removing item from the list: ${myList}');// Remove item using removeAt()var res = myList.removeAt(3);// Print resultprint('The Item removed: ${res}');print('The new list after removing the list element ${myList}');}
Line 3: We create a list called myList
with seven elements.
Line 8: We use the removeAt()
method to remove an item from the index position 3
.
Lines 10 and 12: We display the result.
We can see that pen
, the element at index position 3
, is removed.