Hello Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to check an array is empty or not in typescript, here we will use array length to check array has value or not but before checking the array, we have to check the array is defined or not.

Let start today tutorial How to check an array is empty in typescript?

for check array is defined, we are able to use typeof operator or for check empty array we have to just use array.length syntax.

First, let’s create a new array with no elements.

const arr: Array<Object> = [];

Now we can check if the array is empty by using .length.


This will return 0, as there are 0 items in the array.

const users: Array<Object> = [];

if(typeof users !== "undefined" && users.length == 0){
  console.log("Array is empty");