I have a javascript query like this that is meant to check both undefined
arrays and empty
arrays:
if(array){
if(array.length > 0){
function1();
}else{
function2();
}
}else{
function2();
}
I've tried something like
if(array && ( array.length > 0)){
function1();
}else{
function2();
}
but no dice, get a variable is undefined
error. According to this answer doing if(variable)
works just fine for this use-case, but this only works on strings rather than arrays. Is there any way to do two-in-one in javascript in a case like this?