优秀的编程知识分享平台

网站首页 > 技术文章 正文

js:判断数组是否为空(js中判断数组是否为空)

nanyue 2024-07-30 03:28:14 技术文章 10 ℃

//判断数组是否为空

if (Array.isArray(array) && array.length) {

// array exists and is not empty

}

//判断数组是否为空

const isNotEmpty = arr => Array.isArray(arr) && arr.length > 0;

// console.log(isNotEmpty([1, 2, 3])); // Result: true

//console.log(isNotEmpty([])); // Result: false

最近发表
标签列表