let list = [
{id: "008",title: "标题一",checked: false},
{id: "009",title: "标题二",checked: true},
{id: "010",title: "标题三",checked: true},
{id: "011",title: "标题四",checked: false}
];
// let result = list.map(m => {
// if (m.checked) return m.id;
// })
// console.log(result);// [undefined, "009", "010", undefined]
const filterUndefined = item => typeof item !== 'undefined';
let result = list.map(m => {
if (m.checked) return m.id;
}).filter(filterUndefined);
console.log(result);// ["009", "010"]
特别声明:文章有少部分为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!
作者: 小枫枫,
转载或复制请以
超链接形式 并注明出处 小枫枫不疯喔。
原文地址:
《过滤掉JS中数组使用map处理数据后出现undefined》 发布于2021-7-21
##私密评论仅博主可见##
回复了dd:
##私密评论仅博主可见##
回复了dd:6666666
回复了dd:6666666
回复了dd:6666666
回复了dd:6666666