void main() {
var details = {'LastName':'Martin','FirstName':'Pierre'};
print(details.keys);
}
It will produce the following output : (LastName, FirstName)
But How can I print "LastName" only ?
print(details.keys.toList().first);
As defined in dart docs the method Map.keys returns an Iterable object, that is in iteself an iterable (List) like object. You can access the first element of an iterable with the first getter method. And you can use last to access the last element of an Iterable
void main() {
var details = {'LastName':'Martin','FirstName':'Pierre'};
print(details.keys.first); //LastName
print(details.keys.last); //FirstName
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With