.removeAt()
Published May 30, 2024
Contribute to Docs
The .removeAt()
method in Dart removes an object at a specified index from a list. The remaining elements in the list are shifted to fill the gap.
Syntax
E removeAt(int index)
index
: The index of the object to be removed.
Note: The index must be in the range, 0 ≤ index < length of list.
Example
void main() {List<int> numbers = [1, 2, 3, 4, 5];print("Original list: $numbers");int removedValue = numbers.removeAt(2);print("Removed element: $removedValue");print("Updated list: $numbers");}
The output of the above code is:
Original list: [1, 2, 3, 4, 5]Removed element: 3Updated list: [1, 2, 4, 5]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.