We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这里判断一个数组是否为空,第一个判断没输出是因为数组arr跟null是2个不同的数据类型,数组arr是引用类型存放在堆内存,null是基础类型存放在栈内存,空数组[]也是保存在堆内存但是引用的地址不一样,解决办法是把数组转换成字符串,再判断长度是否> 0
let arr = [] if(arr === null || arr === []) { console.log('arr数组为空') } if(arr.toString().length > 0) { console.log('数组有数据') }else { console.log('数组为空')// 只输出这句 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
这里判断一个数组是否为空,第一个判断没输出是因为数组arr跟null是2个不同的数据类型,数组arr是引用类型存放在堆内存,null是基础类型存放在栈内存,空数组[]也是保存在堆内存但是引用的地址不一样,解决办法是把数组转换成字符串,再判断长度是否> 0
The text was updated successfully, but these errors were encountered: