how to filter null values from map in Dart

前端 未结 4 1688
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 09:49

Following the map, having both key-value pair as dynamic, Write a logic to filter all the null values from Map without us?

Is there any other approach than traversin

4条回答
  •  忘掉有多难
    2021-01-13 10:52

    I suggest you to use removeWhere function

        Map map = {
          '1': 'one',
          '2': null,
          '3': 'three'
        };
    
        map.removeWhere((key, value) => key == null || value == null);
        print(map);
    

提交回复
热议问题