Navigate back to the homepage

how to check array is null or not in typescript?

September 4th, 2022 · 1 min read

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.

1if(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.

1let arr: any = [];
3if(arr && arr.length){
4 console.log("arr is have data")
5} else {
6 console.log("arr is havn't data")
9let arr1: any = null;
11if(arr1 && arr1.length){
12 console.log("arr1 is have data")
13} else {
14 console.log("arr1 is havn't data")

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

how to check array or not in typescript?

An example of check array or not in typeScript with the step-by-step guide.

September 3rd, 2022 · 1 min read

how to get string after last slash in javascript?

An example of get string after last slash in javascript with the step-by-step guide.

August 29th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]