How to check an array is empty or not using jQuery ? Last Updated : 13 Jan, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will check if an array is empty or not using jQuery. In JavaScript, arrays are a special type of object. If we use the typeof operator for arrays, it returns "object". We can use jQuery's isEmptyObject() method to check whether the array is empty or contains elements. The isEmptyObject() method accepts a single parameter of type Object, which is the object to be checked and returns a boolean value true if the object is empty and false if not empty. Syntax: $.isEmptyObject(array); Example 1: In the example below, we passed an empty array to the isEmptyObject() method. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- jQuery CDN Link --> <script src= "https://code.jquery.com/jquery-2.1.3.js"> </script> <style> body { margin: 30px; font-family: sans-serif; text-align: center; } button { padding: 20px; background-color: green; color: white; cursor: pointer; } </style> <!-- Function to check if array is empty --> <script> function checkArray() { var array = []; if($.isEmptyObject(array)) { $("#write").text("The Array is Empty."); }else { $("#write").text("The Array is not Empty."); } } </script> </head> <body> <button id="button1" onclick="checkArray();"> CHECK ARRAY </button> <h2 id="write"></h2> </body> </html> Output: Example 2: In this example, we passed a non-empty array to the isEmptyObject() method. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Check whether the array is empty or not using jQuery </title> <!-- jQuery CDN Link --> <script src= "https://code.jquery.com/jquery-2.1.3.js"> </script> <style> body { margin-top: 30px; font-family: sans-serif; text-align: center; } button { padding: 20px; background-color: green; color: white; cursor: pointer; } </style> <!-- Function to check if array is empty --> <script> function checkArray() { var array = [20, 49, "gfg"]; if ($.isEmptyObject(array)) { $("#write").text("The Array is Empty."); } else { $("#write").text("The Array is not Empty."); } } </script> </head> <body> <button id="button1" onclick="checkArray();"> CHECK ARRAY </button> <h2 id="write"></h2> </body> </html> Output: Comment More infoAdvertise with us Next Article How to check an array is empty or not using jQuery ? V vpsop Follow Improve Article Tags : Web Technologies JQuery jQuery-Questions Similar Reads How to check an HTML element is empty using jQuery ? Given an HTML document and select an element from the HTML document and check that element is empty or not. There are two methods used to solve this problem which are discussed below: Method 1: Using the ":empty" selector: The element to be checked using is() method. The is() method is used to check 3 min read How to Check an Object is Empty using JavaScript? These are the following ways that can be used to Check an Object is Empty using JavaScript: 1. Using Object.keys() Method - Mostly usedThe Object.keys() method returns an array that contains the property names of an object. If the length of array is 0, then object is empty.JavaScriptlet obj = {}; if 2 min read How to check input file is empty or not using JavaScript/jQuery ? Given an HTML document containing an input element, the task is to check whether an input element is empty or not with the help of JavaScript. These are the two approaches to check input file is empty or not using JavaScript/jQuery: Table of Content Using element.files.length property in JavaScript 2 min read Check if an Array is Empty or not in TypeScript In TypeScript, while performing any operation on the array, it is quite important that there should be elements or data in the array, else no operation can be done. We can check whether the array contains the elements or not by using the below-listed methods: Table of Content Using length PropertyUs 2 min read Check if an array is empty or not in JavaScript These are the following ways to check whether the given array is empty or not:1. The length Property - mostly usedThe length property can be used to get the length of the given array if it returns 0 then the length of the array is 0 means the given array is empty else the array have the elements.Jav 1 min read Like