JS中去除数组中的假值(0, 空,undefined, null, false) |
您所在的位置:网站首页 › false的值 › JS中去除数组中的假值(0, 空,undefined, null, false) |
标签:undefined compact 数组 布尔 null das ash name efi 1.Array.filter() arr.filter(Boolean)2.也可以通过遍历判断数组, 空字符,undefined, null, false , 0转化为布尔类型都是 false; let arr=[1, , null, false, undefined, 3]let newArr= []//法1arr.forEach(item => { if (item) { newArr.push(item) }})//法2for (let item of arr) { if (item) { newArr.push(item) }}3.第三方库方法 如 Lodash 库 compact方法 JS中去除数组中的假值(0, 空,undefined, null, false) 标签:undefined compact 数组 布尔 null das ash name efi 原文地址:https://www.cnblogs.com/zhulinxianxain/p/12604739.html |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |