Checks if values are empty including arrays, objects, strings, arguments objects, and jQuery-like collections.
npx @tessl/cli install tessl/npm-lodash-isempty@3.0.0The modern build of lodash's _.isEmpty utility function exported as a standalone Node.js module. Provides comprehensive empty-checking functionality for various JavaScript data types including arrays, objects, strings, arguments objects, and jQuery-like collections.
npm install lodash.isemptyvar isEmpty = require('lodash.isempty');var isEmpty = require('lodash.isempty');
// Check primitive values
isEmpty(null); // => true
isEmpty(undefined); // => true
isEmpty(true); // => true
isEmpty(1); // => true
// Check collections
isEmpty([]); // => true
isEmpty([1, 2, 3]); // => false
isEmpty({}); // => true
isEmpty({ 'a': 1 }); // => false
isEmpty(''); // => true
isEmpty('hello'); // => falseChecks if a value is considered empty across various JavaScript data types.
/**
* Checks if `value` is empty. A value is considered empty unless it's an
* `arguments` object, array, string, or jQuery-like collection with a length
* greater than `0` or an object with own enumerable properties.
*
* @static
* @memberOf _
* @category Lang
* @param {Array|Object|string} value The value to inspect.
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
*/
function isEmpty(value);Behavior:
true for null and undefined valuestrue for primitive values (numbers, booleans, symbols)true if length is 0true if no own enumerable properties existsplice method (jQuery-like collections): treated as array-likeUsage Examples:
var isEmpty = require('lodash.isempty');
// Null and undefined
isEmpty(null); // => true
isEmpty(undefined); // => true
// Primitives
isEmpty(true); // => true
isEmpty(false); // => true
isEmpty(0); // => true
isEmpty(42); // => true
isEmpty(NaN); // => true
// Strings
isEmpty(''); // => true
isEmpty('hello'); // => false
isEmpty(' '); // => false (whitespace counts as content)
// Arrays
isEmpty([]); // => true
isEmpty([1, 2, 3]); // => false
isEmpty(new Array(3)); // => false (sparse arrays have length)
// Objects
isEmpty({}); // => true
isEmpty({ a: 1 }); // => false
isEmpty({ length: 0 }); // => false (has enumerable property)
// Arguments objects
function testArgs() {
return isEmpty(arguments);
}
testArgs(); // => true
testArgs(1, 2); // => false
// Array-like objects (jQuery-style)
isEmpty({ 0: 'a', length: 1, splice: Array.prototype.splice }); // => false
isEmpty({ length: 0, splice: Array.prototype.splice }); // => true
// Functions (treated as objects)
isEmpty(function() {}); // => true
isEmpty(function() { this.a = 1; }); // => true (function object has no enumerable properties)
// Date objects
isEmpty(new Date()); // => true (Date objects have no enumerable properties)