Advertisement
Hiteshw11

Return Map Keys To A List

Nov 23rd, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.34 KB | Source Code | 0 0
  1. /* Write a Dart function that takes a map and returns a list of the map's keys. */
  2.  
  3.  
  4. void main() {
  5.   Map<String,int> mapper = {'apple':1,'banana':2,'orange':3};
  6.   print(mapKeys(mapper));
  7. }
  8.  
  9. List<String> mapKeys(mapper)
  10. {
  11. List<String> abc =[];
  12. for(MapEntry <String,int> e in mapper.entries)
  13. {
  14. abc.add(e.key);
  15. }
  16. return abc;
  17.  
  18. }
  19.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement