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 ? 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 How to check element exists or not in jQuery ? Checking if an element exists in jQuery involves selecting the element and verifying its length. If the selected element's length is greater than 0, the element exists in the DOM; otherwise, it doesn't. This is useful for conditionally manipulating elements. There are two ways to check whether an el 3 min read How to check an element is exists in array or not in PHP ? An array may contain elements belonging to different data types, integer, character, or logical type. The values can then be inspected in the array using various in-built methods : Approach 1 (Using in_array() method): The array() method can be used to declare an array. The in_array() method in PHP 2 min read How to check a string data type is present in array using JavaScript ? In JavaScript, an array is a collection of data that can be of the same or different type. If we have the array containing the data, our task is to identify if it is a string data type. In this article, we will learn how to use the typeof operator. Syntax: typeof value Note: The typeof operator retu 3 min read How to check a selector matches some content using jQuery? In order to know whether the jQuery selector selected any element or not, Here 2 methods are discussed and these are mostly used methods. Example-1: In this example, Selector searches for <p> element. This example uses the length property to check If something is selected or not. In this case 2 min read How to check an element contains a class using jQuery? Method 1: Using hasClass() method: The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exists or not. It returns a boolean value specifying whether the class exists in the element or not. This can be used to check for multiple classes. Syntax: 2 min read Like