Dart .containsValue()
Published Jul 12, 2024
Contribute to Docs
In Dart, the .containsValue() method is used to check if a particular value is present in a Map. If the value exists, the method returns true. Otherwise, it returns false.
Syntax
newMap.containsValue(val)
newMap: TheMapto be checked.val: The value to be searched for.
Example
The following example demonstrates the usage of the .containsValue() method:
void main() {// Creating a MapMap newMap = {1: 'Cricket', 2: 'Football', 3: 'Tennis'};// Checking if 'Tennis' exists in the Mapprint(newMap.containsValue('Tennis'));}
The above code produces the following output:
true
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