Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Check If an Array Exists and Not Empty</title> </head> <body> <script> // Sample variable var myVar = [1, 2, 3]; // Testing variable if(typeof myVar != 'undefined' && Array.isArray(myVar) && myVar.length > 0) { document.write("The array exists and it is not empty."); } else { document.write("The variable failed the test."); } </script> </body> </html>