.containsValue()

Anonymous contributor's avatar
Anonymous contributor
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: The Map to be checked.
  • val: The value to be searched for.

Example

The following example demonstrates the usage of the .containsValue() method:

void main() {
// Creating a Map
Map newMap = {1: 'Cricket', 2: 'Football', 3: 'Tennis'};
// Checking if 'Tennis' exists in the Map
print(newMap.containsValue('Tennis'));
}

The above code produces the following output:

true

All contributors

Contribute to Docs

Learn Dart on Codecademy