Removing selected keys from a Dart card

What is a Dart idiomatic way to remove selected keys from a card? Below I use a temporary pool of List to store String keys. Is there a cleaner way?

List<String> emptyList = new List<String>(); _objTable.keys.forEach((String name) { if (_objTable[name].indices.isEmpty) { emptyList.add(name); print("OBJ: deleting empty object=$name loaded from url=$url"); } }); emptyList.forEach((String name) => _objTable.remove(name)); 
+8
dart map
source share
1 answer

You can do something like this:

 _objTable.keys .where((k) => _objTable[k].indices.isEmpty) // filter keys .toList() // create a copy to avoid concurrent modifications .forEach(_objTable.remove); // remove selected keys 
+8
source share

All Articles