es6 map 过滤 对象为null 的数据
可以使用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。
原文地址: http://www.cveoy.top/t/topic/iroS 著作权归作者所有。请勿转载和采集!