Dart Map values
Syntax & Examples
Syntax of Map.values
The syntax of Map.values property is:
Iterable<V> values
This values property of Map the values of this
Map object.
Return Type
Map.values returns value of type Iterable<V>
.
✐ Examples
1 Get all values in a map of integers
In this example,
- We create a map named
map
with key-value pairs containing integers. - We use the
values
property ofmap
to get all values as an iterable. - We print all values to standard output.
Dart Program
void main() {
var map = {'a': 1, 'b': 2, 'c': 3};
var allValues = map.values;
print('All values in the map: $allValues');
}
Output
All values in the map: (1, 2, 3)
2 Get all values in a map of strings
In this example,
- We create a map named
map
with key-value pairs containing strings. - We use the
values
property ofmap
to get all values as an iterable. - We print all values to standard output.
Dart Program
void main() {
var map = {'one': 'uno', 'two': 'dos', 'three': 'tres'};
var allValues = map.values;
print('All values in the map: $allValues');
}
Output
All values in the map: (uno, dos, tres)
3 Get all values in a map of mixed types
In this example,
- We create a map named
map
with key-value pairs containing mixed types (string and integer). - We use the
values
property ofmap
to get all values as an iterable. - We print all values to standard output.
Dart Program
void main() {
var map = {'apple': 1, 'banana': 2, 'cherry': 3};
var allValues = map.values;
print('All values in the map: $allValues');
}
Output
All values in the map: (1, 2, 3)
Summary
In this Dart tutorial, we learned about values property of Map: the syntax and few working examples with output and detailed explanation for each example.