Determine whether the array is empty - the wrong way
const arr = []
if (arr) {
console.log('true')
} else {
console.log('false')
}
// true
为什么空数组为 true 呢?
We found an empty array deployed inside or have a default property
Determine whether the array is empty - the correct way
if (arr && arr.length > 0) {
console.log('true')
}
Determine whether an array is empty, it must determine thelength > 0