lodash.compact
创建一个新数组,包含原数组中所有的非假值元素。例如false, null,0, "", undefined, 和 NaN 都是被认为是“假值”
function compact(array){
if(!array || typeof array !== 'object') return []
let result = []
for(let i = 0; i < array.length; i++){
if(!(i in array)) continue;
if(array[i]){
result.push(array[i])
}
}
return array
}
console.log(compact([0, 1, false, 2, '', 3]))