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.00
# lodash.isempty
1
2
The 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.
3
4
## Package Information
5
6
- **Package Name**: lodash.isempty
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.isempty`
10
11
## Core Imports
12
13
```javascript
14
var isEmpty = require('lodash.isempty');
15
```
16
17
## Basic Usage
18
19
```javascript
20
var isEmpty = require('lodash.isempty');
21
22
// Check primitive values
23
isEmpty(null); // => true
24
isEmpty(undefined); // => true
25
isEmpty(true); // => true
26
isEmpty(1); // => true
27
28
// Check collections
29
isEmpty([]); // => true
30
isEmpty([1, 2, 3]); // => false
31
isEmpty({}); // => true
32
isEmpty({ 'a': 1 }); // => false
33
isEmpty(''); // => true
34
isEmpty('hello'); // => false
35
```
36
37
## Capabilities
38
39
### Empty Value Detection
40
41
Checks if a value is considered empty across various JavaScript data types.
42
43
```javascript { .api }
44
/**
45
* Checks if `value` is empty. A value is considered empty unless it's an
46
* `arguments` object, array, string, or jQuery-like collection with a length
47
* greater than `0` or an object with own enumerable properties.
48
*
49
* @static
50
* @memberOf _
51
* @category Lang
52
* @param {Array|Object|string} value The value to inspect.
53
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
54
*/
55
function isEmpty(value);
56
```
57
58
**Behavior:**
59
- Returns `true` for `null` and `undefined` values
60
- Returns `true` for primitive values (numbers, booleans, symbols)
61
- For array-like values (arrays, strings, arguments objects, jQuery-like collections): returns `true` if length is 0
62
- For objects (including functions, Date objects, etc.): returns `true` if no own enumerable properties exist
63
- For functions with a `splice` method (jQuery-like collections): treated as array-like
64
65
**Usage Examples:**
66
67
```javascript
68
var isEmpty = require('lodash.isempty');
69
70
// Null and undefined
71
isEmpty(null); // => true
72
isEmpty(undefined); // => true
73
74
// Primitives
75
isEmpty(true); // => true
76
isEmpty(false); // => true
77
isEmpty(0); // => true
78
isEmpty(42); // => true
79
isEmpty(NaN); // => true
80
81
// Strings
82
isEmpty(''); // => true
83
isEmpty('hello'); // => false
84
isEmpty(' '); // => false (whitespace counts as content)
85
86
// Arrays
87
isEmpty([]); // => true
88
isEmpty([1, 2, 3]); // => false
89
isEmpty(new Array(3)); // => false (sparse arrays have length)
90
91
// Objects
92
isEmpty({}); // => true
93
isEmpty({ a: 1 }); // => false
94
isEmpty({ length: 0 }); // => false (has enumerable property)
95
96
// Arguments objects
97
function testArgs() {
98
return isEmpty(arguments);
99
}
100
testArgs(); // => true
101
testArgs(1, 2); // => false
102
103
// Array-like objects (jQuery-style)
104
isEmpty({ 0: 'a', length: 1, splice: Array.prototype.splice }); // => false
105
isEmpty({ length: 0, splice: Array.prototype.splice }); // => true
106
107
// Functions (treated as objects)
108
isEmpty(function() {}); // => true
109
isEmpty(function() { this.a = 1; }); // => true (function object has no enumerable properties)
110
111
// Date objects
112
isEmpty(new Date()); // => true (Date objects have no enumerable properties)
113
```