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.0The 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.
npm install lodash@2.4.1For lodash v2.4.1 (the main lodash package):
const _ = require('lodash');
// Use _.isObject(value)ES6 modules (if using a bundler with lodash):
import _ from 'lodash';
// Use _.isObject(value)Direct function access:
const { isObject } = require('lodash');
// Use isObject(value)const _ = require('lodash');
// Check objects
_.isObject({});
// => true
_.isObject({ name: 'Alice', age: 30 });
// => true
// Check arrays (they are objects in JavaScript)
_.isObject([1, 2, 3]);
// => true
_.isObject([]);
// => true
// Check functions (they are objects in JavaScript)
_.isObject(function() {});
// => true
// Check regex (objects in JavaScript)
_.isObject(/abc/);
// => true
// Check dates (objects in JavaScript)
_.isObject(new Date());
// => true
// Check wrapper objects
_.isObject(new Number(0));
// => true
_.isObject(new String(''));
// => true
// Check primitives (not objects)
_.isObject(1);
// => false
_.isObject('hello');
// => false
_.isObject(true);
// => false
// Check null (not an object per ECMAScript spec)
_.isObject(null);
// => false
// Check undefined
_.isObject(undefined);
// => falseDetermines 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.
/**
* Checks if value is the language type of Object.
* (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
*
* @param {*} value The value to check.
* @returns {boolean} Returns true if the value is an object, else false.
*/
function isObject(value)Behavior:
true for: objects {}, arrays [], functions, regexes /pattern/, Date objects, wrapper objects (new Number(0), new String(''))false for: null, primitives (numbers, strings, booleans), undefinedImplementation Details:
objectTypes lookup table to map typeof results to boolean valuesUsage Examples:
const _ = require('lodash');
// Type checking in conditional logic
function processValue(value) {
if (_.isObject(value)) {
// Handle objects, arrays, functions, etc.
console.log('Processing object-type value');
return Object.keys(value).length;
} else {
// Handle primitives
console.log('Processing primitive value');
return String(value).length;
}
}
// Filtering arrays by object type
const mixedArray = [1, 'hello', {}, [], function() {}, null, true];
const objectsOnly = mixedArray.filter(_.isObject);
// Result: [{}, [], function() {}]
// Validation in data processing
function validateInput(data) {
if (!_.isObject(data)) {
throw new Error('Input must be an object');
}
// Process the object...
}Since this is a JavaScript library without TypeScript definitions in v2.4.1, type information is provided as JSDoc comments:
/**
* Internal lookup table used by isObject to determine object types
* Maps typeof results to boolean values indicating whether they represent objects
*/
var objectTypes = {
'boolean': false,
'function': true,
'object': true,
'number': false,
'string': false,
'undefined': false
};The isObject function does not throw errors. It safely handles all JavaScript values including:
null and undefined valuesThe function always returns a boolean value and never throws exceptions.
This function works in all JavaScript environments supported by lodash v2.4.1:
The implementation includes specific workarounds for V8 engine bugs to ensure consistent behavior across different environments.