_.compact(array)
创建一个新数组,包含原数组中所有的非假值元素。例如false
, null
,0
, ""
, undefined
, 和 NaN
都是被认为是“假值”。
<template>
<div></div>
</template>
<script>
import _ from "lodash"; // 引入
export default {
data() {
return {};
},
mounted() {
console.log(this.checkIsData());
},
methods: {
//创建一个新数组,包含原数组中所有的非假值元素。例如false, null,0, "", undefined, 和 NaN 都是被认为是“假值”。
checkIsData() {
const arr = [0, 1, false, 2, "", 3, {}];
const newArr = _.compact(arr);
const lenth = newArr.length;
return { newArr: newArr, lenth: lenth };
},
},
};
</script>