Tutorial Details

How to Check Array Is Empty Or Null In Javascript?
20 Sep

How to Check Array Is Empty Or Null In Javascript?

Hi Guys,

In this tutorial we will learn about How to Check Array Is Empty Or Null In Javascript.

Let's begin tutorial

<!DOCTYPE html>
<html>
<head>
    <title>How to Check Array Is Empty Or Null In Javascript?</title>
</head>
<body>
  
<script type="text/javascript">
   
    /*
      Basic Checking for Jquery Array
    */
    var myArray = [1, 2, 3];
  
    if (myArray && myArray.length > 0) {
        console.log('myArray is not empty.');
    }else{
        console.log('myArray is empty.');
    }
  
    /*
      Basic Checking with an empty array for Jquery Array
    */
    var myArray2 = [];
  
    if (myArray2 && myArray2.length > 0) {
        console.log('myArray2 is not empty.');
    }else{
        console.log('myArray2 is empty.');
    }
  
    /*
      Basic Checking with an undefined array for Jquery Array
    */
    if (typeof myArray3 !== 'undefined' && myArray3.length > 0) {
        console.log('myArray3 is not empty.');
    }else{
        console.log('myArray3 is empty.');
    }
  
    /*
      Basic Checking with a null array for Jquery Array
    */
    var myArray4 = null;
   
    if (myArray4 && myArray4.length > 0) {
        console.log('myArray4 is not empty.');
    }else{
        console.log('myArray4 is empty.');
    }
   
</script>
</body>
</html>

 

0 Comments

Leave a Comment