Dart .removeWhere()
Anonymous contributor
Published Jan 7, 2026
Contribute to Docs
In Dart, the .removeWhere() method removes key–value pairs from a Map when a given condition evaluates to true. The condition is provided as a function that is applied to each key and value in the map.
Syntax
map.removeWhere((key, value) => condition);
Parameters:
key: The current key in the map.value: The value associated with the key.condition: A function that returnstruefor entries that should be removed.
Return value:
The .removeWhere() method returns void. The map is modified in place.
Example: Removing entries based on a condition
In this example, entries with scores below 60 are removed from the map:
void main() {Map<String, int> scores = {'Alice': 85,'Bob': 42,'Charlie': 67,};// Remove entries where the score is below 60scores.removeWhere((name, score) => score < 60);print(scores);}
The output of this code is:
{Alice: 85, Charlie: 67}
All contributors
- Anonymous contributor
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.
Learn Dart on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours