3

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

Javascript:

var data = [];

Jade:

if(data) 
   table ...
else 
   table ...
Alvin
  • 8,219
  • 25
  • 96
  • 177

2 Answers2

12

Use length property:

if (data.length)
    table ...
else
    table ...
alexpods
  • 47,475
  • 10
  • 100
  • 94
4

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

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

here is a related answer https://stackoverflow.com/a/5071150/3556874

Community
  • 1
  • 1
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88