Skip to content

Object Functions

A collection of utility functions for working with objects.

deepClone

Creates a deep clone of an object or array.

const original = {
name: 'John',
settings: { theme: 'dark', notifications: true },
tags: ['important', 'new']
};
const cloned = deepClone(original);
console.log(cloned); // Deep copy of the original object
console.log(cloned === original); // false
console.log(cloned.settings === original.settings); // false

pick

Creates an object composed of the picked object properties.

const object = { a: 1, b: 2, c: 3, d: 4 };
const picked = pick(object, ['a', 'c']);
console.log(picked); // { a: 1, c: 3 }

omit

Creates an object composed of all properties from the input object except those specified in the keys array.

const object = { a: 1, b: 2, c: 3, d: 4 };
const omitted = omit(object, ['a', 'c']);
console.log(omitted); // { b: 2, d: 4 }
// Works with inherited properties too
class Parent {
parentProp = 'parent value';
}
class Child extends Parent {
childProp = 'child value';
}
const instance = new Child();
const result = omit(instance, ['childProp']);
console.log(result); // { parentProp: 'parent value' }

merge

Deeply merges two objects.

const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 }, e: 4 };
const merged = merge(obj1, obj2);
console.log(merged); // { a: 1, b: { c: 2, d: 3 }, e: 4 }