dart
Dart program for condition based item removal from a list
If you want to remove items from a list based on one or multiple conditions then you can use the .removeWhere() method of dart list.
void main() {
List<Map<String, dynamic>> names = [
{ "id": 1, "name": "John" },
{ "id": 2, "name": "Rick" },
{ "id": 3, "name": "Daryl" },
{ "id": 4, "name": "Alex" }
];
// Remove items if id is greater than or equals to 3
names.removeWhere((item) => item['id'] >= 3);
print(names);
}
If you want to remove items based on two conditions where the name is Rick and id is two then you can use the below syntax.
names.removeWhere((item) => item['id'] == 2 && item['name'] == 'Rick');
Was this helpful?
Similar Posts
- Stop a Loop condition based in Dart
- Dart Program to add Single or Multiple Items to a List
- Dart Program to update or replace List items or values
- Dart Program to remove the last element from a List
- Dart Program to remove multiple items from a List at once
- Dart program to remove duplicate items from a list
- Remove List item or element using its index in Dart