- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.9.x
- Description
- A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
- Author
- tessl
- Last updated
object-methods.md docs/
1# Object Methods23Deep object operations including property access, merging, transformation, and key/value manipulation for comprehensive object handling.45## Capabilities67### Assign89Assigns own enumerable string keyed properties of source objects to the destination object.1011```javascript { .api }12/**13* Assigns own enumerable string keyed properties of source objects to the14* destination object. Source objects are applied from left to right.15* Subsequent sources overwrite property assignments of previous sources.16* @param object - The destination object17* @param sources - The source objects18* @returns Returns `object`19*/20function assign<TObject, TSource>(object: TObject, source: TSource): TObject & TSource;21function assign<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;22function assign<TObject>(object: TObject, ...otherArgs: any[]): any;23```2425### Assign In2627Like assign except that it iterates over own and inherited source properties.2829```javascript { .api }30/**31* This method is like `assign` except that it iterates over own and32* inherited source properties.33* @param object - The destination object34* @param sources - The source objects35* @returns Returns `object`36*/37function assignIn<TObject, TSource>(object: TObject, source: TSource): TObject & TSource;38function assignIn<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;39function assignIn<TObject>(object: TObject, ...otherArgs: any[]): any;40```4142### Assign In With4344Like assignIn except that it accepts customizer which is invoked to produce the assigned values.4546```javascript { .api }47/**48* This method is like `assignIn` except that it accepts `customizer`49* which is invoked to produce the assigned values.50* @param object - The destination object51* @param sources - The source objects52* @param customizer - The function to customize assigned values53* @returns Returns `object`54*/55function assignInWith<TObject, TSource>(56object: TObject,57source: TSource,58customizer: (objValue: any, srcValue: any, key: string, object: TObject, source: TSource) => any59): TObject & TSource;60function assignInWith<TObject>(object: TObject, ...otherArgs: any[]): any;61```6263### Assign With6465Like assign except that it accepts customizer which is invoked to produce the assigned values.6667```javascript { .api }68/**69* This method is like `assign` except that it accepts `customizer` which70* is invoked to produce the assigned values.71* @param object - The destination object72* @param sources - The source objects73* @param customizer - The function to customize assigned values74* @returns Returns `object`75*/76function assignWith<TObject, TSource>(77object: TObject,78source: TSource,79customizer: (objValue: any, srcValue: any, key: string, object: TObject, source: TSource) => any80): TObject & TSource;81function assignWith<TObject>(object: TObject, ...otherArgs: any[]): any;82```8384### Create8586Creates an object that inherits from the prototype object.8788```javascript { .api }89/**90* Creates an object that inherits from the `prototype` object. If a91* `properties` object is given, its own enumerable string keyed properties92* are assigned to the created object.93* @param prototype - The object to inherit from94* @param properties - The properties to assign to the object95* @returns Returns the new object96*/97function create<T>(prototype: T, properties?: PropertyDescriptorMap): T;98```99100### Defaults101102Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined.103104```javascript { .api }105/**106* Assigns own and inherited enumerable string keyed properties of source107* objects to the destination object for all destination properties that108* resolve to `undefined`. Source objects are applied from left to right.109* Once a property is set, additional values of the same property are ignored.110* @param object - The destination object111* @param sources - The source objects112* @returns Returns `object`113*/114function defaults<TObject, TSource>(object: TObject, source: TSource): TSource & TObject;115function defaults<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TSource2 & TSource1 & TObject;116function defaults<TObject>(object: TObject, ...sources: any[]): any;117```118119### Defaults Deep120121Like defaults except that it recursively assigns default properties.122123```javascript { .api }124/**125* This method is like `defaults` except that it recursively assigns126* default properties.127* @param object - The destination object128* @param sources - The source objects129* @returns Returns `object`130*/131function defaultsDeep<TObject, TSource>(object: TObject, source: TSource): TSource & TObject;132function defaultsDeep<TObject>(object: TObject, ...sources: any[]): any;133```134135### Find Key136137This method is like find except that it returns the key of the first element predicate returns truthy for instead of the element itself.138139```javascript { .api }140/**141* This method is like `find` except that it returns the key of the first142* element `predicate` returns truthy for instead of the element itself.143* @param object - The object to inspect144* @param predicate - The function invoked per iteration145* @returns Returns the key of the matched element, else `undefined`146*/147function findKey<T>(148object: T,149predicate?: string | object | ((value: T[keyof T], key: string, object: T) => boolean)150): string | undefined;151```152153### Find Last Key154155Like findKey except that it iterates over elements in the opposite order.156157```javascript { .api }158/**159* This method is like `findKey` except that it iterates over elements of160* a collection in the opposite order.161* @param object - The object to inspect162* @param predicate - The function invoked per iteration163* @returns Returns the key of the matched element, else `undefined`164*/165function findLastKey<T>(166object: T,167predicate?: string | object | ((value: T[keyof T], key: string, object: T) => boolean)168): string | undefined;169```170171### For In172173Iterates over own and inherited enumerable string keyed properties of an object and invokes iteratee for each property.174175```javascript { .api }176/**177* Iterates over own and inherited enumerable string keyed properties of an178* object and invokes `iteratee` for each property. The iteratee is invoked179* with three arguments: (value, key, object). Iteratee functions may exit180* iteration early by explicitly returning `false`.181* @param object - The object to iterate over182* @param iteratee - The function invoked per iteration183* @returns Returns `object`184*/185function forIn<T>(186object: T,187iteratee?: (value: T[keyof T], key: string, object: T) => any188): T;189```190191### For In Right192193Like forIn except that it iterates over properties in the opposite order.194195```javascript { .api }196/**197* This method is like `forIn` except that it iterates over properties of198* `object` in the opposite order.199* @param object - The object to iterate over200* @param iteratee - The function invoked per iteration201* @returns Returns `object`202*/203function forInRight<T>(204object: T,205iteratee?: (value: T[keyof T], key: string, object: T) => any206): T;207```208209### For Own210211Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.212213```javascript { .api }214/**215* Iterates over own enumerable string keyed properties of an object and216* invokes `iteratee` for each property. The iteratee is invoked with three217* arguments: (value, key, object). Iteratee functions may exit iteration218* early by explicitly returning `false`.219* @param object - The object to iterate over220* @param iteratee - The function invoked per iteration221* @returns Returns `object`222*/223function forOwn<T>(224object: T,225iteratee?: (value: T[keyof T], key: string, object: T) => any226): T;227```228229### For Own Right230231Like forOwn except that it iterates over properties in the opposite order.232233```javascript { .api }234/**235* This method is like `forOwn` except that it iterates over properties of236* `object` in the opposite order.237* @param object - The object to iterate over238* @param iteratee - The function invoked per iteration239* @returns Returns `object`240*/241function forOwnRight<T>(242object: T,243iteratee?: (value: T[keyof T], key: string, object: T) => any244): T;245```246247### Functions248249Creates an array of function property names from own enumerable properties of object.250251```javascript { .api }252/**253* Creates an array of function property names from own enumerable properties254* of `object`.255* @param object - The object to inspect256* @returns Returns the function names257*/258function functions(object?: any): string[];259```260261### Functions In262263Creates an array of function property names from own and inherited enumerable properties of object.264265```javascript { .api }266/**267* Creates an array of function property names from own and inherited268* enumerable properties of `object`.269* @param object - The object to inspect270* @returns Returns the function names271*/272function functionsIn(object?: any): string[];273```274275### Get276277Gets the value at path of object.278279```javascript { .api }280/**281* Gets the value at `path` of `object`. If the resolved value is282* `undefined`, the `defaultValue` is returned in its place.283* @param object - The object to query284* @param path - The path of the property to get285* @param defaultValue - The value returned for `undefined` resolved values286* @returns Returns the resolved value287*/288function get<TObject extends object, TKey extends keyof TObject>(289object: TObject,290path: TKey | [TKey]291): TObject[TKey];292function get<TObject extends object, TKey extends keyof TObject, TDefault>(293object: TObject | null | undefined,294path: TKey | [TKey],295defaultValue: TDefault296): TObject[TKey] | TDefault;297function get<T>(298object: any,299path: PropertyPath,300defaultValue?: T301): T;302```303304### Has305306Checks if path is a direct property of object.307308```javascript { .api }309/**310* Checks if `path` is a direct property of `object`.311* @param object - The object to query312* @param path - The path to check313* @returns Returns `true` if `path` exists, else `false`314*/315function has<T>(object: T, path: PropertyPath): boolean;316```317318### Has In319320Checks if path is a direct or inherited property of object.321322```javascript { .api }323/**324* Checks if `path` is a direct or inherited property of `object`.325* @param object - The object to query326* @param path - The path to check327* @returns Returns `true` if `path` exists, else `false`328*/329function hasIn<T>(object: T, path: PropertyPath): boolean;330```331332### Invert333334Creates an object composed of the inverted keys and values of object.335336```javascript { .api }337/**338* Creates an object composed of the inverted keys and values of `object`.339* If `object` contains duplicate values, subsequent values overwrite340* property assignments of previous values.341* @param object - The object to invert342* @returns Returns the new inverted object343*/344function invert(object: any): Record<string, string>;345```346347### Invert By348349Like invert except that the inverted object is generated from the results of running each element of object thru iteratee.350351```javascript { .api }352/**353* This method is like `invert` except that the inverted object is generated354* from the results of running each element of `object` thru `iteratee`.355* The corresponding inverted value of each inverted key is an array of keys356* responsible for generating the inverted value.357* @param object - The object to invert358* @param iteratee - The iteratee invoked per element359* @returns Returns the new inverted object360*/361function invertBy<T>(362object: Record<PropertyKey, T>,363iteratee?: string | ((value: T) => PropertyKey)364): Record<string, string[]>;365```366367### Invoke368369Invokes the method at path of object.370371```javascript { .api }372/**373* Invokes the method at `path` of `object`.374* @param object - The object to query375* @param path - The path of the method to invoke376* @param args - The arguments to invoke the method with377* @returns Returns the result of the invoked method378*/379function invoke(object: any, path: PropertyPath, ...args: any[]): any;380```381382### Keys383384Creates an array of the own enumerable property names of object.385386```javascript { .api }387/**388* Creates an array of the own enumerable property names of `object`.389* @param object - The object to query390* @returns Returns the array of property names391*/392function keys(object?: any): string[];393```394395### Keys In396397Creates an array of the own and inherited enumerable property names of object.398399```javascript { .api }400/**401* Creates an array of the own and inherited enumerable property names of `object`.402* @param object - The object to query403* @returns Returns the array of property names404*/405function keysIn(object?: any): string[];406```407408### Map Keys409410Creates an object with the same values as object and keys generated by running each own enumerable string keyed property of object thru iteratee.411412```javascript { .api }413/**414* Creates an object with the same values as `object` and keys generated415* by running each own enumerable string keyed property of `object` thru416* `iteratee`. The iteratee is invoked with three arguments:417* (value, key, object).418* @param object - The object to iterate over419* @param iteratee - The function invoked per iteration420* @returns Returns the new mapped object421*/422function mapKeys<T>(423object: Record<string, T> | undefined,424iteratee?: string | ((value: T, key: string, object: Record<string, T>) => PropertyKey)425): Record<string, T>;426```427428### Map Values429430Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru iteratee.431432```javascript { .api }433/**434* Creates an object with the same keys as `object` and values generated435* by running each own enumerable string keyed property of `object` thru436* `iteratee`. The iteratee is invoked with three arguments:437* (value, key, object).438* @param object - The object to iterate over439* @param iteratee - The function invoked per iteration440* @returns Returns the new mapped object441*/442function mapValues<T, R>(443object: Record<string, T> | undefined,444iteratee: string | ((value: T, key: string, object: Record<string, T>) => R)445): Record<string, R>;446function mapValues<T>(447object: Record<string, T> | undefined,448iteratee?: string449): Record<string, any>;450```451452### Merge453454Recursively merges own and inherited enumerable string keyed properties of source objects into the destination object.455456```javascript { .api }457/**458* This method is like `assign` except that it recursively merges own and459* inherited enumerable string keyed properties of source objects into the460* destination object. Source properties that resolve to `undefined` are461* skipped if a destination value exists. Array and plain object properties462* are merged recursively.463* @param object - The destination object464* @param sources - The source objects465* @returns Returns `object`466*/467function merge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource;468function merge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;469function merge<TObject>(object: TObject, ...otherArgs: any[]): any;470```471472### Merge With473474Like merge except that it accepts customizer which is invoked to produce the merged values of the destination and source properties.475476```javascript { .api }477/**478* This method is like `merge` except that it accepts `customizer` which479* is invoked to produce the merged values of the destination and source480* properties.481* @param object - The destination object482* @param sources - The source objects483* @param customizer - The function to customize assigned values484* @returns Returns `object`485*/486function mergeWith<TObject, TSource>(487object: TObject,488source: TSource,489customizer: (objValue: any, srcValue: any, key: string, object: TObject, source: TSource, stack: any) => any490): TObject & TSource;491function mergeWith<TObject>(object: TObject, ...otherArgs: any[]): any;492```493494### Omit495496Creates an object composed of the own and inherited enumerable property paths of object that are not omitted.497498```javascript { .api }499/**500* The opposite of `pick`; this method creates an object composed of the501* own and inherited enumerable property paths of `object` that are not omitted.502* @param object - The source object503* @param paths - The property paths to omit504* @returns Returns the new object505*/506function omit<T, K extends keyof T>(object: T, ...paths: K[]): Omit<T, K>;507function omit<T>(object: T, ...paths: PropertyPath[]): Partial<T>;508```509510### Omit By511512The opposite of pickBy; this method creates an object composed of the own and inherited enumerable string keyed properties of object that predicate doesn't return truthy for.513514```javascript { .api }515/**516* The opposite of `pickBy`; this method creates an object composed of517* the own and inherited enumerable string keyed properties of `object` that518* `predicate` doesn't return truthy for. The predicate is invoked with two519* arguments: (value, key).520* @param object - The source object521* @param predicate - The function invoked per property522* @returns Returns the new object523*/524function omitBy<T>(525object: Record<string, T> | undefined,526predicate?: string | ((value: T, key: string) => boolean)527): Record<string, T>;528```529530### Pick531532Creates an object composed of the picked object properties.533534```javascript { .api }535/**536* Creates an object composed of the picked `object` properties.537* @param object - The source object538* @param paths - The property paths to pick539* @returns Returns the new object540*/541function pick<T, K extends keyof T>(object: T, ...paths: K[]): Pick<T, K>;542function pick<T>(object: T, ...paths: PropertyPath[]): Partial<T>;543```544545### Pick By546547Creates an object composed of the object properties predicate returns truthy for.548549```javascript { .api }550/**551* Creates an object composed of the `object` properties `predicate` returns552* truthy for. The predicate is invoked with two arguments: (value, key).553* @param object - The source object554* @param predicate - The function invoked per property555* @returns Returns the new object556*/557function pickBy<T>(558object: Record<string, T> | undefined,559predicate?: string | ((value: T, key: string) => boolean)560): Record<string, T>;561```562563### Result564565Gets the value at path of object.566567```javascript { .api }568/**569* This method is like `get` except that if the resolved value is a570* function it's invoked with the `this` binding of its parent object and571* its result is returned.572* @param object - The object to query573* @param path - The path of the property to resolve574* @param defaultValue - The value returned for `undefined` resolved values575* @returns Returns the resolved value576*/577function result<T>(object: any, path: PropertyPath, defaultValue?: T): T;578```579580### Set581582Sets the value at path of object.583584```javascript { .api }585/**586* Sets the value at `path` of `object`. If a portion of `path` doesn't exist,587* it's created. Arrays are created for missing index properties while objects588* are created for all other missing properties.589* @param object - The object to modify590* @param path - The path of the property to set591* @param value - The value to set592* @returns Returns `object`593*/594function set<T>(object: T, path: PropertyPath, value: any): T;595```596597### Set With598599Like set except that it accepts customizer which is invoked to produce the objects of path.600601```javascript { .api }602/**603* This method is like `set` except that it accepts `customizer` which is604* invoked to produce the objects of `path`.605* @param object - The object to modify606* @param path - The path of the property to set607* @param value - The value to set608* @param customizer - The function to customize assigned values609* @returns Returns `object`610*/611function setWith<T>(612object: T,613path: PropertyPath,614value: any,615customizer?: (nsValue: any, key: string, nsObject: T) => any616): T;617```618619### To Pairs620621Creates an array of own enumerable string keyed-value pairs for object.622623```javascript { .api }624/**625* Creates an array of own enumerable string keyed-value pairs for `object`626* which can be consumed by `fromPairs`. If `object` is a map or set, its627* entries are returned.628* @param object - The object to query629* @returns Returns the key-value pairs630*/631function toPairs<T>(object?: Record<PropertyKey, T>): Array<[string, T]>;632```633634### To Pairs In635636Creates an array of own and inherited enumerable string keyed-value pairs for object.637638```javascript { .api }639/**640* Creates an array of own and inherited enumerable string keyed-value641* pairs for `object` which can be consumed by `fromPairs`.642* @param object - The object to query643* @returns Returns the key-value pairs644*/645function toPairsIn<T>(object?: Record<PropertyKey, T>): Array<[string, T]>;646```647648### To Path649650Converts value to a property path array.651652```javascript { .api }653/**654* Converts `value` to a property path array.655* @param value - The value to convert656* @returns Returns the new property path array657*/658function toPath(value: any): string[];659```660661### Transform662663An alternative to reduce; this method transforms object to a new accumulator object which is the result of running each of its own enumerable string keyed properties thru iteratee.664665```javascript { .api }666/**667* An alternative to `reduce`; this method transforms `object` to a new668* `accumulator` object which is the result of running each of its own669* enumerable string keyed properties thru `iteratee`, with each invocation670* potentially mutating the `accumulator` object.671* @param object - The object to iterate over672* @param iteratee - The function invoked per iteration673* @param accumulator - The custom accumulator value674* @returns Returns the accumulated value675*/676function transform<T, TResult>(677object: Record<string, T>,678iteratee: (accumulator: TResult, value: T, key: string, object: Record<string, T>) => void,679accumulator?: TResult680): TResult;681function transform<T, TResult>(682object: T[],683iteratee: (accumulator: TResult, value: T, index: number, array: T[]) => void,684accumulator?: TResult685): TResult;686```687688### Unset689690Removes the property at path of object.691692```javascript { .api }693/**694* Removes the property at `path` of `object`.695* @param object - The object to modify696* @param path - The path of the property to unset697* @returns Returns `true` if the property is deleted, else `false`698*/699function unset<T>(object: T, path: PropertyPath): boolean;700```701702### Update703704This method is like set except that accepts updater to produce the value to set.705706```javascript { .api }707/**708* This method is like `set` except that accepts `updater` to produce the709* value to set. Use `updateWith` to customize `path` creation.710* @param object - The object to modify711* @param path - The path of the property to set712* @param updater - The function to produce the updated value713* @returns Returns `object`714*/715function update<T>(object: T, path: PropertyPath, updater: (value: any) => any): T;716```717718### Update With719720This method is like update except that it accepts customizer which is invoked to produce the objects of path.721722```javascript { .api }723/**724* This method is like `update` except that it accepts `customizer` which is725* invoked to produce the objects of `path`.726* @param object - The object to modify727* @param path - The path of the property to set728* @param updater - The function to produce the updated value729* @param customizer - The function to customize assigned values730* @returns Returns `object`731*/732function updateWith<T>(733object: T,734path: PropertyPath,735updater: (value: any) => any,736customizer?: (nsValue: any, key: string, nsObject: T) => any737): T;738```739740### Values741742Creates an array of the own enumerable string keyed property values of object.743744```javascript { .api }745/**746* Creates an array of the own enumerable string keyed property values of `object`.747* @param object - The object to query748* @returns Returns the array of property values749*/750function values<T>(object?: Record<PropertyKey, T>): T[];751```752753### Values In754755Creates an array of the own and inherited enumerable string keyed property values of object.756757```javascript { .api }758/**759* Creates an array of the own and inherited enumerable string keyed property760* values of `object`.761* @param object - The object to query762* @returns Returns the array of property values763*/764function valuesIn<T>(object?: Record<PropertyKey, T>): T[];765```766767## Types768769```javascript { .api }770type PropertyPath = string | number | symbol | Array<string | number | symbol>;771type PropertyKey = string | number | symbol;772```773774## Aliases775776- `entries` → `toPairs`777- `entriesIn` → `toPairsIn`778- `extend` → `assignIn`779- `extendWith` → `assignInWith`