Checks if a value is the ECMAScript language type of Object (arrays, functions, objects, regexes, etc.)
npx @tessl/cli install tessl/npm-lodash-isobject@2.4.00
# Lodash isObject
1
2
The `lodash.isobject` package provides the `isObject` utility function from lodash v2.4.1. This function checks if a value is the ECMAScript language type of Object, including arrays, functions, objects, regexes, and other object types, but excluding null and primitives.
3
4
## Package Information
5
6
- **Package Name**: lodash.isobject
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: In v2.4.1, this functionality is part of the main lodash package: `npm install lodash@2.4.1`
10
11
## Core Imports
12
13
For lodash v2.4.1 (the main lodash package):
14
15
```javascript
16
const _ = require('lodash');
17
// Use _.isObject(value)
18
```
19
20
ES6 modules (if using a bundler with lodash):
21
22
```javascript
23
import _ from 'lodash';
24
// Use _.isObject(value)
25
```
26
27
Direct function access:
28
29
```javascript
30
const { isObject } = require('lodash');
31
// Use isObject(value)
32
```
33
34
## Basic Usage
35
36
```javascript
37
const _ = require('lodash');
38
39
// Check objects
40
_.isObject({});
41
// => true
42
43
_.isObject({ name: 'Alice', age: 30 });
44
// => true
45
46
// Check arrays (they are objects in JavaScript)
47
_.isObject([1, 2, 3]);
48
// => true
49
50
_.isObject([]);
51
// => true
52
53
// Check functions (they are objects in JavaScript)
54
_.isObject(function() {});
55
// => true
56
57
// Check regex (objects in JavaScript)
58
_.isObject(/abc/);
59
// => true
60
61
// Check dates (objects in JavaScript)
62
_.isObject(new Date());
63
// => true
64
65
// Check wrapper objects
66
_.isObject(new Number(0));
67
// => true
68
69
_.isObject(new String(''));
70
// => true
71
72
// Check primitives (not objects)
73
_.isObject(1);
74
// => false
75
76
_.isObject('hello');
77
// => false
78
79
_.isObject(true);
80
// => false
81
82
// Check null (not an object per ECMAScript spec)
83
_.isObject(null);
84
// => false
85
86
// Check undefined
87
_.isObject(undefined);
88
// => false
89
```
90
91
## Capabilities
92
93
### Object Type Checking
94
95
Determines if a value is the ECMAScript language type of Object. This includes arrays, functions, objects, regexes, Date objects, and wrapper objects, but excludes null and primitives.
96
97
```javascript { .api }
98
/**
99
* Checks if value is the language type of Object.
100
* (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
101
*
102
* @param {*} value The value to check.
103
* @returns {boolean} Returns true if the value is an object, else false.
104
*/
105
function isObject(value)
106
```
107
108
**Behavior:**
109
- Returns `true` for: objects `{}`, arrays `[]`, functions, regexes `/pattern/`, Date objects, wrapper objects (`new Number(0)`, `new String('')`)
110
- Returns `false` for: `null`, primitives (numbers, strings, booleans), `undefined`
111
112
**Implementation Details:**
113
- Uses internal `objectTypes` lookup table to map `typeof` results to boolean values
114
- Handles V8 engine bug workarounds for consistent behavior across environments
115
- Follows ECMAScript specification for Object type determination
116
117
**Usage Examples:**
118
119
```javascript
120
const _ = require('lodash');
121
122
// Type checking in conditional logic
123
function processValue(value) {
124
if (_.isObject(value)) {
125
// Handle objects, arrays, functions, etc.
126
console.log('Processing object-type value');
127
return Object.keys(value).length;
128
} else {
129
// Handle primitives
130
console.log('Processing primitive value');
131
return String(value).length;
132
}
133
}
134
135
// Filtering arrays by object type
136
const mixedArray = [1, 'hello', {}, [], function() {}, null, true];
137
const objectsOnly = mixedArray.filter(_.isObject);
138
// Result: [{}, [], function() {}]
139
140
// Validation in data processing
141
function validateInput(data) {
142
if (!_.isObject(data)) {
143
throw new Error('Input must be an object');
144
}
145
// Process the object...
146
}
147
```
148
149
## Types
150
151
Since this is a JavaScript library without TypeScript definitions in v2.4.1, type information is provided as JSDoc comments:
152
153
```javascript { .api }
154
/**
155
* Internal lookup table used by isObject to determine object types
156
* Maps typeof results to boolean values indicating whether they represent objects
157
*/
158
var objectTypes = {
159
'boolean': false,
160
'function': true,
161
'object': true,
162
'number': false,
163
'string': false,
164
'undefined': false
165
};
166
```
167
168
## Error Handling
169
170
The `isObject` function does not throw errors. It safely handles all JavaScript values including:
171
- `null` and `undefined` values
172
- All primitive types
173
- All object types
174
- Edge cases and unusual values
175
176
The function always returns a boolean value and never throws exceptions.
177
178
## Browser and Environment Support
179
180
This function works in all JavaScript environments supported by lodash v2.4.1:
181
- All modern browsers
182
- Node.js
183
- Rhino
184
- Other JavaScript engines
185
186
The implementation includes specific workarounds for V8 engine bugs to ensure consistent behavior across different environments.