可以使用filter方法来实现对对象为null的数据进行过滤。

const data = new Map([
  ['a', null],
  ['b', 'value'],
  ['c', null],
]);

const filteredData = new Map([...data].filter(([key, value]) => value !== null));

console.log(filteredData);
// Output: Map(1) { 'b' => 'value' }

在上面的例子中,我们使用[...data]将Map转换为数组,然后使用filter方法对数组进行过滤,保留value不为null的项。最后再将过滤后的数组转换回Map。

es6 map 过滤 对象为null 的数据

原文地址: http://www.cveoy.top/t/topic/iroS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录