es6怎么判断数组是否为空
时间:2022-03-09 19:43
es6判断数组是否为空的方法:1、使用“arr.length == 0”语句,判断数组的长度是否为0,如果为0则为空;2、使用“JSON.stringify(arr) === '[]'”语句,如果返回值为false则为空。 本教程操作环境:windows7系统、ECMAScript 6版、Dell G3电脑。 es6判断数组是否为空的方法 方法1:利用length属性 方法2:利用JSON.stringify() 【相关推荐:javascript视频教程、web前端】 以上就是es6怎么判断数组是否为空的详细内容,更多请关注gxlsystem.com其它相关文章!let arr = [];
if (arr.length == 0){
console.log("数组为空")
}else {
console.log("数组不为空")
}
let arr = [1,2,3];
if (JSON.stringify(arr) === '[]'){
console.log("数组为空")
}else {
console.log("数组不为空")
}