Hi Friends 👋,
Welcome To Infinitbility! ❤️
To check array is null or not in typeScript, use if...else
statement it will handle all falsy value like undefined
, null
, empty
and etc.
Let’s see short example to use if...else
with array
to check a array is null in typeScript.
if(array && array.length){
}
Today, I’m going to show you How do I check array is null or not in typeScript, as above mentioned, I’m going to use the above-mentioned if...else
statement.
Let’s start today’s tutorial how do you check array is null or not in typeScript?
TypeScript check array is null or not example
Here, we will take string variable with some data and use if...else
statement to check array is null or not.
let arr: any = [];
if(arr && arr.length){
console.log("arr is have data")
} else {
console.log("arr is havn't data")
}
let arr1: any = null;
if(arr1 && arr1.length){
console.log("arr1 is have data")
} else {
console.log("arr1 is havn't data")
}
I hope it helps you, All the best 👍.