Const
Performs a deep equality check between two values, comparing all nested properties.
The first value to compare
The second value to compare
True if the values are deeply equal, false otherwise
ObjectUtils.deepEqual({ a: { b: 1 } }, { a: { b: 1 } }); // Returns true
ObjectUtils.deepEqual({ a: 1 }, { a: 2 }); // Returns false
ObjectUtils.deepEqual([1, 2, 3], [1, 2, 3]); // Returns true
Filters an array of objects to unique values based on a specified property.
An array containing only unique objects based on the specified property
const users = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' },
{ id: 1, name: 'John Doe' }
];
ObjectUtils.filterUniqueByProp(users, 'id'); // Returns first two objects
Filters an object to only include the specified keys.
The object to filter
An array of keys to include in the filtered object
A new object containing only the specified keys
const user = { id: 1, name: 'John', email: 'john@example.com', password: 'secret' };
ObjectUtils.filterByKeys(user, ['id', 'name']); // Returns { id: 1, name: 'John' }
Finds the index of the first non-zero value in an object of numbers.
An object containing numeric values
The index of the first non-zero value, or -1 if all values are zero
ObjectUtils.findFirstNonZeroIndex({ a: 0, b: 0, c: 5, d: 2 }); // Returns 2
ObjectUtils.findFirstNonZeroIndex({ a: 0, b: 0 }); // Returns -1
Flattens a nested object into a single-level object with dot-notation keys.
The object to flatten
The prefix to use for nested keys (default: empty string)
A flattened object with dot-notation keys
const nested = { user: { profile: { name: 'John', age: 30 } } };
ObjectUtils.flatten(nested);
// Returns { 'user.profile.name': 'John', 'user.profile.age': 30 }
Checks if an object conforms to a set of rules
True if object conforms to all rules
Replaces a key in an object
New object with replaced key
Transforms an object's keys and/or values
Object to transform
Optional
keyTransform: ((key) => string)Function to transform keys
Optional
valueTransform: ((value) => unknown)Function to transform values
Transformed object
Creates a deep clone of an object, including nested objects and arrays.