EN
TypeScript - check if array is empty
0 points
Using TypeScript it is possible to check if an array is empty in the following way.
Note:
Array.isArray(array)
method can be useful too to check if constialbe is array type.
xxxxxxxxxx
1
const array1 = [];
2
const array2 = [1, 2, 3];
3
const array3 = [false];
4
const array4 = [
5
() => {
6
return false;
7
},
8
];
9
const array5 = [{ result: false }];
10
11
console.log(array1.length == 0); // true
12
console.log(array2.length == 0); // false
13
console.log(array3.length == 0); // false
14
console.log(array4.length == 0); // false
15
console.log(array5.length == 0); // false
Output:
xxxxxxxxxx
1
true
2
false
3
false
4
false
5
false