Dart .removeWhere()
Published Mar 15, 2024
Contribute to Docs
The .removeWhere() method removes elements from a list, based on a given condition that is provided as an argument.
Syntax
void removeWhere(bool Function(E element))
Function (element E): It defines the condition for removal. If the function evaluates totruefor a value in the list, then the value is removed from the list.
Example
This example demonstrates using .removeWhere() to remove even numbers from a list, resulting in a list of odd numbers.
void main() {List<int> numbers = [1,2,3,4,5,6,7,8,9,10];numbers.removeWhere((int number) => number % 2 ==0);print(numbers);}
The above code will return the following output:
[1, 3, 5, 7, 9]
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