Languages
[Edit]
EN

TypeScript - check if array is empty or does not exist

0 points
Created by:
Paluskitten
356

In this article, we're going to have a look at how to check if the array is empty or does not exist in TypeScript code.

Quick solution:

 

1. Practical example

Edit

In this section two approaches were presented: when the variable is not defined and when is defined but with null or undefined value.

1.1. If we are not sure the variable is defined.

Edit

Note: using typeof operator we are able to check if variable exists and is defined - this operator checks if varialbe exists.

Output:

1.2. Variable is created but we are not sure if the variable is assigned.

Edit

The approach presented in this section is based on the fact the variables were declared. Using variable == null comparison we are able to test both conditions at the same time: value is null or undefined

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join