1 | initial version |
A particular map value can be accessed using its key in Dart by using the square bracket notation. For example:
Map<String, int> ages = {'Alice': 32, 'Bob': 28, 'Charlie': 45};
int aliceAge = ages['Alice']; // accessing the value of the key 'Alice'
print(aliceAge); // Output: 32
In this example, we have a map called ages
which has a key-value pair for each person's name and age. To access Alice's age, we simply use ages['Alice']
which returns the value associated with the key 'Alice'. It can be stored in a variable or used directly wherever needed.