How to know if a value is empty

If I pass an empty array to jade, how can I know if it is empty?

JavaScript:

var data = [];

      

Jade:

if(data) 
   table ...
else 
   table ...

      

+3


source to share


2 answers


Use property length

:



if (data.length)
    table ...
else
    table ...

      

+11


source


you can use javascript to check the length of the array.

if (data.length==0){
  // do something array is empty
}

      



here is the related answer from fooobar.com/questions/77088 / ...

+4


source







All Articles