Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if array is null or empty?

I want to check if my array is empty or null, and on base of which I want to create a condition for example.

if(array ==  EMPTY){ //do something } 

I hope I'm clear what I am asking, just need to check if my array is empty?

regards

like image 696
Shishir.bobby Avatar asked Oct 18 '10 12:10

Shishir.bobby


People also ask

How do you check if an array is empty or null?

To check if an array is null, use equal to operator and check if array is equal to the value null. In the following example, we will initialize an integer array with null. And then use equal to comparison operator in an If Else statement to check if array is null. The array is empty.

How do I check if a string array is empty?

To check if an array contains an empty string, call the includes() method passing it an empty string - includes('') . The includes method returns true if the provided value is contained in the array and false otherwise.

How check array is empty or not in Javascript?

The array can be checked if it is empty by using the array. length property. This property returns the number of elements in the array. If the number is greater than 0, it evaluates to true.

How check array is empty or not in C#?

To check if an given array is empty or not, we can use the built-in Array. Length property in C#. Alternatively, we can also use the Array. Length property to check if a array is null or empty in C#.


1 Answers

if (!array || !array.count){   ... } 

That checks if array is not nil, and if not - check if it is not empty.

like image 100
Vladimir Avatar answered Sep 22 '22 10:09

Vladimir