去掉数组中的空数组
使用filter(查看)
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
注意: filter() 不会对空数组进行检测。
注意: filter() 不会改变原始数组。
let aa=[
[{name:'小红',age:18,class:1},{name:'小明',age:18,class:1}],
[],
[{name:'小黄',age:18,class:2},{name:'小蓝',age:18,class:2}],
[{name:'小紫',age:18,class:3}],
[{name:'小橙',age:18,class:3}]
]
var r = aa.filter(item => {
return item.length > 0
});
console.log(r)
结果:
[
[{name:'小红',age:18,class:1},{name:'小明',age:18,class:1}],
[{name:'小黄',age:18,class:2},{name:'小蓝',age:18,class:2}],
[{name:'小紫',age:18,class:3}],
[{name:'小橙',age:18,class:3}]
]