What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For a JavaScript array, check array.length === 0. jQuery does not change how JavaScript arrays work. If you mean a jQuery selector result, check the collection’s .length instead.
Check whether a JavaScript array is empty
An array is empty when its length is zero:
if (array.length === 0) {
// The array has no slots
}
To check for the opposite condition, use array.length > 0. The array’s length counts its slots, not just slots that have assigned values. MDN explains how array length works.
Check the type first if the value is uncertain
If a variable might not contain an array, use the native Array.isArray() check before reading its length:
if (Array.isArray(value) && value.length === 0) {
// value is an empty array
}
Array.isArray() returns false for values such as null, undefined, ordinary objects, and typed arrays. It also recognizes arrays created in another JavaScript realm, where instanceof Array can fail. See MDN’s Array.isArray() reference.
#1 Best Overall
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Check a jQuery selector result separately
A jQuery selection returns a jQuery collection, not a plain JavaScript array. To determine whether a selector matched anything, check the collection’s .length:
if ($(selector).length === 0) {
// No elements matched
}
For example, if ($(".notice").length) is also a valid truthy check for whether the selection found at least one element. An unmatched selector produces an empty jQuery object with .length equal to 0. The jQuery constructor documentation describes selector results.
Rank #2
- JavaScript Jquery
- Introduces core programming concepts in JavaScript and jQuery
- Uses clear descriptions, inspiring examples, and easy-to-follow diagrams
Why $.isEmptyObject() is not the array check
$.isEmptyObject() checks whether an object has enumerable properties; it is not the semantic test for whether an array has zero slots. The jQuery API says: “Check to see if an object is empty (contains no enumerable properties).” It also says the argument should generally be a plain JavaScript object. For array emptiness, use the array’s length. jQuery.isEmptyObject() API documentation.
Empty slots and sparse arrays
length === 0 answers whether an array has zero slots. A sparse array can contain unassigned slots and still have a positive length; therefore, this check does not tell you how many slots contain assigned values. If your application needs to distinguish those cases, define and check that condition separately.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use current native APIs
The jQuery API index marks jQuery.isArray() as deprecated in jQuery 3.2 and removed, and jQuery.isEmptyObject() as deprecated in jQuery 3.3 and removed. For array type validation, use Array.isArray(); for emptiness, inspect .length. jQuery 3.2 API changes and jQuery 3.3 API changes.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




