es6 Method to determine whether the array is empty: 1. Use the "arr.length == 0" statement to determine whether the length of the array is 0. If it is 0, it is empty; 2. Use "JSON.stringify" (arr) === '[]'" statement, if the return value is false, it will be empty.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
es6 method to determine whether the array is empty
Method 1: Use the length attribute
let arr = []; if (arr.length == 0){ console.log("数组为空") }else { console.log("数组不为空") }
Method 2: Using JSON.stringify()
let arr = [1,2,3]; if (JSON.stringify(arr) === '[]'){ console.log("数组为空") }else { console.log("数组不为空") }
[Related recommendations: javascript video Tutorial、web front-end】
The above is the detailed content of How to determine whether an array is empty in es6. For more information, please follow other related articles on the PHP Chinese website!