Object functions
Perform various manipulation and mutation operations with objects.
assign()
Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
Aliases: extend(), assign_in().
assign(object [, source1 [, source2 [...]]])
Arguments
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
assign_in()
Alias for assign().
assign_with()
This function is like assign() except that it accepts customizer which is invoked to produce the assigned values. If customizer returns undefined, assignment is handled by the function instead. The customizer is invoked with an array of five arguments: [objValue, srcValue, key, object, source].
Aliases: extend_with().
assign_with(object, source, [customizer])
Arguments
object(Object)- The destination object.
source(Object)- The source object.
customizer(Expression)- (Optional) The function to customize assigned values. Default value is
&[1]
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
assign_in_with()
Alias for assign_with().
at()
Creates an array of values corresponding to paths of object.
at(object, [paths])
Arguments
Returns
- (Array)
- The picked values.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
defaults()
Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined. Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.
defaults(object, [sources])
Arguments
Returns
- (Array)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
defaults_deep()
This method is like defaults() except that it recursively assigns default properties.
defaults_deep(object, [sources])
Arguments
Returns
- (Array)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
entries()
Alias for to_pairs().
entries_in()
Alias for to_pairs().
extend()
Alias for assign().
extend_with()
Alias for assign_with().
get()
Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
get(object, path, [defaultValue])
Arguments
object(Object)- The object to query.
path(Array | String)- The path of the property to get.
defaultValue(Any)- The value returned for undefined resolved values.
Returns
- (Any)
- The resolved value.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
| | |
has()
Checks if path is a direct property of object.
has(object, path)
Arguments
Returns
- (Any)
trueifpathexists, elsefalse.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
| | |
has_in()
Alias for has().
invert()
Creates an object composed of the inverted keys and values of object. If object contains duplicate values, subsequent values overwrite property assignments of previous values.
invert(object)
Arguments
object(Object)- The object to invert.
Returns
- (Object)
- The new inverted object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
invert_by()
This function is like invert() except that the inverted object is generated from the results of running each element of object thru iteratee. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. The iteratee is invoked with one argument: @ (current element).
invert_by(object, [iteratee])
Arguments
object(Object)- The object to invert.
iteratee(Expression | Array | Object | String)- (Optional) The expression invoked per iteration. The
iterateeexpression is invoked with one argument:@(current element). Default value is&@.
Returns
- (Object)
- The new inverted object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
| | |
keys()
Creates an array of the own enumerable property names of object.
keys(object)
Arguments
object(Object)- The object to query.
Returns
- (Array)
- The array of property names.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
keys_in()
Alias for keys().
map_keys()
The opposite of map_values(). This function creates an object with the same values as object and keys generated by running each own enumerable string keyed property of object thru mapper. The mapper is invoked with an array of three named arguments: [value, key, object].
map_keys(object, [mapper])
Arguments
object(Any)- The object to iterate over.
mapper(Expression | Array | Object | String)- (Optional) The expression invoked per iteration. Expression signature is
(value, key, object). Default value is&key.
Returns
- (Object)
- The new mapped object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
map_values()
Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru mapper. The mapper is invoked with an array of three named arguments: [value, key, object].
map_values(object, [mapper])
Arguments
object(Any)- The object to iterate over.
mapper(Expression | Array | Object | String)- (Optional) The expression invoked per iteration. Expression signature is
(value, key, object). Default value is&value.
Returns
- (Object)
- The new mapped object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
merge()
This function is like assign() except that it recursively merges own and inherited enumerable string keyed properties of source objects into the destination object. Source properties that resolve to undefined are skipped if a destination value exists. Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
merge(object, [sources])
Arguments
Returns
- (Object)
- The
object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
omit()
The opposite of pick(); this function creates an object composed of the own enumerable property paths of object excluding the omitted paths.
omit(object, [paths])
Arguments
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
omit_by()
The opposite of pick_by(); this function creates an object composed of the own enumerable string keyed properties of object that predicate doesn't return truthy for. The predicate is invoked with an array of two arguments: [value, key].
omit_by(object, [predicate])
Arguments
object(Object)- The source object.
predicate(Expression | Array | Object | String)- (Optional) The expression, invoked per iteration. Default value is
&[0]
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
| | |
| | |
pick()
Creates an object composed of the picked object properties included in paths.
pick(object, [paths])
Arguments
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
pick_by()
Creates an object composed of the object properties predicate returns truthy for. The predicate is invoked with an array of two arguments: [value, key].
pick_by(object, [predicate])
Arguments
object(Object)- The source object.
predicate(Expression | Array | Object | String)- (Optional) The expression, invoked per iteration. Default value is
&[0]
Returns
- (Object)
- The new object.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
| | |
| | |
set()
Sets the value at path of object. If a portion of path doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties.
set(object, path, value)
Arguments
object(Object)- The object to modify.
path(String | Array)- The path of the property to set.
value(Any)- The value to set.
Returns
- (Object)
- The
object
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
to_pairs()
Creates an array of own enumerable string keyed-value pairs for object which can be consumed by from_pairs().
Aliases: entries(), entries_in(), to_pairs_in().
to_pairs(object)
Arguments
object(Object)- The object to query.
Returns
- (Array)
- The key-value pairs.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
to_pairs_in()
Alias for to_pairs().
unset()
Removes the property at path of object.
unset(object, path)
Arguments
Returns
- (Object)
- The
object
Examples
| Input | Expression | Result |
|---|---|---|
| | |
update()
This function is like set() except that accepts updater to produce the value to set. The updater is invoked with one argument: (value).
update(object, path, updater)
Arguments
object(Object)- The object to modify.
path(Array | String)- The path of the property to set.
updater(Expression)- The expression to produce the updated value.
Returns
- (Object)
- The
object
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
values()
Creates an array of the own enumerable string keyed property values of object.
values(object)
Arguments
object(Object)- The object to query.
Returns
- (Object)
- The array of property values.
Examples
| Input | Expression | Result |
|---|---|---|
| | |
| | |
values_in()
Alias for values().