Solved: How to remove the last three elements in a list using Dart?
Question
Asked by Faris S on June 22, 2022 (source).
if you have list like this ...
List<String> data = ['1', '2', '3', '4', '5',..... n];
how can you remove the last three element knowing that you don't know the length of the list, i tried to use removeRange() but it didn't go well.
Answer
Question answered by Ravindra S (source).
Try below code
void main() {
List data = ['1', '2', '3', '4', '5'];
data .length = data.length - 3;//put your how many list item you want to remove eg.1,2,3,...n
print(data);
}
Result-> [1, 2]
SHARE: