Creates a new array concatenating array
with any additional arrays
and/or values.
Optional
Rest
...values: Many<T>[]The array values to concatenate.
Returns the new concatenated array.
var array = [1];
var other = _.concat(array, 2, [3], [[4]]);
console.log(other);
// => [1, 2, 3, [4]]
console.log(array);
// => [1]
This method is like _.difference except that it accepts comparator which is invoked to compare elements of array to values. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
Returns the new array of filtered values.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
_.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
// => [{ 'x': 2, 'y': 1 }]
_.differenceWith
_.differenceWith
_.differenceWith
The inverse of _.toPairs
; this method returns an object composed
from key-value pairs
.
The key-value pairs.
Returns the new object.
_.fromPairs([['fred', 30], ['barney', 40]]);
// => { 'fred': 30, 'barney': 40 }
_.fromPairs
Gets the index at which the first occurrence of value
is found in array
using SameValueZero
for equality comparisons. If fromIndex
is negative, it's used as the offset
from the end of array
.
Returns the index of the matched value, else -1
.
_.indexOf([1, 2, 1, 2], 2);
// => 1
// using `fromIndex`
_.indexOf([1, 2, 1, 2], 2, 2);
// => 3
This method is like _.intersection
except that it accepts iteratee
which is invoked for each element of each arrays
to generate the criterion
by which uniqueness is computed. The iteratee is invoked with one argument: (value).
Returns the new array of shared values.
_.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
// => [2.1]
// using the `_.property` iteratee shorthand
_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }]
_.intersectionBy
_.intersectionBy
_.intersectionBy
_.intersectionBy
Creates an array of unique array
values not included in the other
provided arrays using SameValueZero
for equality comparisons.
Returns the new array of filtered values.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.intersectionWith(objects, others, _.isEqual);
// => [{ 'x': 1, 'y': 2 }]
_.intersectionWith
_.intersectionWith
_.intersectionWith
This method is like _.pull
except that it accepts an array of values to remove.
Note: Unlike _.difference
, this method mutates array
.
Returns array
.
var array = [1, 2, 3, 1, 2, 3];
_.pull(array, [2, 3]);
console.log(array);
// => [1, 1]
_.pullAll
This method is like _.pullAll
except that it accepts iteratee
which is
invoked for each element of array
and values
to to generate the criterion
by which uniqueness is computed. The iteratee is invoked with one argument: (value).
Note: Unlike _.differenceBy
, this method mutates array
.
Returns array
.
var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
_.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
console.log(array);
// => [{ 'x': 2 }]
_.pullAllBy
_.pullAllBy
_.pullAllBy
This method is like _.pullAll
except that it accepts comparator
which is
invoked to compare elements of array to values. The comparator is invoked with
two arguments: (arrVal, othVal).
Note: Unlike _.differenceWith
, this method mutates array
.
Returns array
.
var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
_.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
console.log(array);
// => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
_.pullAllWith
_.pullAllWith
_.pullAllWith
Reverses array
so that the first element becomes the last, the second
element becomes the second to last, and so on.
Note: This method mutates array
and is based on
Array#reverse
.
Returns array
.
var array = [1, 2, 3];
_.reverse(array);
// => [3, 2, 1]
console.log(array);
// => [3, 2, 1]
Uses a binary search to determine the lowest index at which value
should
be inserted into array
in order to maintain its sort order.
Returns the index at which value
should be inserted into array
.
_.sortedIndex([30, 50], 40);
// => 1
_.sortedIndex([4, 5], 4);
// => 0
Uses a binary search to determine the lowest index at which value
should
be inserted into array
in order to maintain its sort order.
Returns the index at which value
should be inserted into array
.
_.sortedIndex([30, 50], 40);
// => 1
_.sortedIndex([4, 5], 4);
// => 0
This method is like _.sortedIndex
except that it accepts iteratee
which is invoked for value
and each element of array
to compute their
sort ranking. The iteratee is invoked with one argument: (value).
Returns the index at which value
should be inserted into array
.
var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 };
_.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
// => 1
// using the `_.property` iteratee shorthand
_.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
// => 0
This method is like _.indexOf
except that it performs a binary
search on a sorted array
.
Returns the index of the matched value, else -1
.
_.sortedIndexOf([1, 1, 2, 2], 2);
// => 2
This method is like _.sortedIndex
except that it returns the highest
index at which value
should be inserted into array
in order to
maintain its sort order.
Returns the index at which value
should be inserted into array
.
_.sortedLastIndex([4, 5], 4);
// => 1
This method is like _.sortedLastIndex
except that it accepts iteratee
which is invoked for value
and each element of array
to compute their
sort ranking. The iteratee is invoked with one argument: (value).
Returns the index at which value
should be inserted into array
.
// using the `_.property` iteratee shorthand
_.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
// => 1
This method is like _.lastIndexOf
except that it performs a binary
search on a sorted array
.
Returns the index of the matched value, else -1
.
_.sortedLastIndexOf([1, 1, 2, 2], 2);
// => 3
This method is like _.union
except that it accepts comparator
which
is invoked to compare elements of arrays
. The comparator is invoked
with two arguments: (arrVal, othVal).
Returns the new array of combined values.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.unionWith(objects, others, _.isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
_.unionWith
_.unionWith
Creates a duplicate-free version of an array, using
SameValueZero
for equality comparisons, in which only the first occurrence of each element
is kept.
The array to inspect.
Returns the new duplicate free array.
_.uniq([2, 1, 2]);
// => [2, 1]
This method is like _.uniq
except that it accepts iteratee
which is
invoked for each element in array
to generate the criterion by which
uniqueness is computed. The iteratee is invoked with one argument: (value).
Returns the new duplicate free array.
_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]
// using the `_.property` iteratee shorthand
_.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
This method is like _.uniq
except that it accepts comparator
which
is invoked to compare elements of array
. The comparator is invoked with
two arguments: (arrVal, othVal).
Returns the new duplicate free array.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.uniqWith(objects, _.isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
This method is like _.xor
except that it accepts iteratee
which is
invoked for each element of each arrays
to generate the criterion by which
uniqueness is computed. The iteratee is invoked with one argument: (value).
Returns the new array of values.
_.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
// => [1.2, 4.3]
// using the `_.property` iteratee shorthand
_.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 2 }]
_.xorBy
_.xorBy
This method is like _.xor
except that it accepts comparator
which is
invoked to compare elements of arrays
. The comparator is invoked with
two arguments: (arrVal, othVal).
Returns the new array of values.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.xorWith(objects, others, _.isEqual);
// => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
_.xorWith
_.xorWith
This method is like _.flatMap
except that it recursively flattens the
mapped results.
Returns the new flattened array.
4.7.0
function duplicate(n) {
return [[[n, n]]];
}
_.flatMapDeep([1, 2], duplicate);
// => [1, 1, 2, 2]
_.flatMapDeep
_.flatMapDeep
_.flatMapDeep
_.flatMapDeep
This method is like _.flatMap
except that it recursively flattens the
mapped results up to depth
times.
Returns the new flattened array.
4.7.0
function duplicate(n) {
return [[[n, n]]];
}
_.flatMapDepth([1, 2], duplicate, 2);
// => [[1, 1], [2, 2]]
_.flatMapDepth
_.flatMapDepth
Optional
depth: number_.flatMapDepth
Optional
depth: number_.flatMapDepth
This method is like _.sortBy
except that it allows specifying the sort
orders of the iteratees to sort by. If orders
is unspecified, all values
are sorted in ascending order. Otherwise, specify an order of "desc" for
descending or "asc" for ascending sort order of corresponding values.
Returns the new sorted array.
var users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 34 },
{ 'user': 'fred', 'age': 42 },
{ 'user': 'barney', 'age': 36 }
];
// sort by `user` in ascending order and by `age` in descending order
_.orderBy(users, ['user', 'age'], ['asc', 'desc']);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
_.orderBy
_.orderBy
_.orderBy
Creates an array of elements, sorted in ascending order by the results of running each element in a collection through each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratees are invoked with one argument: (value).
Returns the new sorted array.
var users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 42 },
{ 'user': 'barney', 'age': 34 }
];
_.sortBy(users, function(o) { return o.user; });
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
_.sortBy(users, ['user', 'age']);
// => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
_.sortBy(users, 'user', function(o) {
return Math.floor(o.age / 10);
});
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
_.sortBy
Creates a function that invokes func
with arguments reversed.
The function to flip arguments for.
Returns the new function.
var flipped = _.flip(function() {
return _.toArray(arguments);
});
flipped('a', 'b', 'c', 'd');
// => ['d', 'c', 'b', 'a']
Performs a SameValueZero
comparison between two values to determine if they are equivalent.
The value to compare.
The other value to compare.
Returns true
if the values are equivalent, else false
.
var object = { 'user': 'fred' };
var other = { 'user': 'fred' };
_.eq(object, object);
// => true
_.eq(object, other);
// => false
_.eq('a', 'a');
// => true
_.eq('a', Object('a'));
// => false
_.eq(NaN, NaN);
// => true
Checks if value
is array-like. A value is considered array-like if it's
not a function and has a value.length
that's an integer greater than or
equal to 0
and less than or equal to Number.MAX_SAFE_INTEGER
.
Returns true
if value
is array-like, else false
.
_.isArrayLike([1, 2, 3]);
// => true
_.isArrayLike(document.body.children);
// => true
_.isArrayLike('abc');
// => true
_.isArrayLike(_.noop);
// => false
_.isArrayLike
_.isArrayLike
This method is like _.isArrayLike
except that it also checks if value
is an object.
The value to check.
Returns true
if value
is an array-like object, else false
.
_.isArrayLikeObject([1, 2, 3]);
// => true
_.isArrayLikeObject(document.body.children);
// => true
_.isArrayLikeObject('abc');
// => false
_.isArrayLikeObject(_.noop);
// => false
_.isArrayLikeObject
_.isArrayLikeObject
Performs a deep comparison between two values to determine if they are equivalent.
Note: This method supports comparing arrays, array buffers, booleans,
date objects, error objects, maps, numbers, Object
objects, regexes,
sets, strings, symbols, and typed arrays. Object
objects are compared
by their own, not inherited, enumerable properties. Functions and DOM
nodes are not supported.
The value to compare.
The other value to compare.
Returns true
if the values are equivalent, else false
.
var object = { 'user': 'fred' };
var other = { 'user': 'fred' };
_.isEqual(object, other);
// => true
object === other;
// => false
This method is like _.isEqual
except that it accepts customizer
which is
invoked to compare values. If customizer
returns undefined
comparisons are
handled by the method instead. The customizer
is invoked with up to seven arguments:
(objValue, othValue [, index|key, object, other, stack]).
The value to compare.
The other value to compare.
Optional
customizer: IsEqualCustomizerThe function to customize comparisons.
Returns true
if the values are equivalent, else false
.
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, othValue) {
if (isGreeting(objValue) && isGreeting(othValue)) {
return true;
}
}
var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];
_.isEqualWith(array, other, customizer);
// => true
Checks if value
is an integer.
Note: This method is based on Number.isInteger
.
Optional
value: anyThe value to check.
Returns true
if value
is an integer, else false
.
_.isInteger(3);
// => true
_.isInteger(Number.MIN_VALUE);
// => false
_.isInteger(Infinity);
// => false
_.isInteger('3');
// => false
Checks if value
is a valid array-like length.
Note: This function is loosely based on ToLength
.
Optional
value: anyThe value to check.
Returns true
if value
is a valid length, else false
.
_.isLength(3);
// => true
_.isLength(Number.MIN_VALUE);
// => false
_.isLength(Infinity);
// => false
_.isLength('3');
// => false
Performs a deep comparison between object
and source
to determine if
object
contains equivalent property values.
Note: This method supports comparing the same values as _.isEqual
.
The object to inspect.
The object of property values to match.
Returns true
if object
is a match, else false
.
var object = { 'user': 'fred', 'age': 40 };
_.isMatch(object, { 'age': 40 });
// => true
_.isMatch(object, { 'age': 36 });
// => false
This method is like _.isMatch
except that it accepts customizer
which
is invoked to compare values. If customizer
returns undefined
comparisons
are handled by the method instead. The customizer
is invoked with three
arguments: (objValue, srcValue, index|key, object, source).
The object to inspect.
The object of property values to match.
Optional
customizer: isMatchWithCustomizerThe function to customize comparisons.
Returns true
if object
is a match, else false
.
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, srcValue) {
if (isGreeting(objValue) && isGreeting(srcValue)) {
return true;
}
}
var object = { 'greeting': 'hello' };
var source = { 'greeting': 'hi' };
_.isMatchWith(object, source, customizer);
// => true
Checks if value
is object-like. A value is object-like if it's not null
and has a typeof
result of "object".
Optional
value: anyThe value to check.
Returns true
if value
is object-like, else false
.
_.isObjectLike({});
// => true
_.isObjectLike([1, 2, 3]);
// => true
_.isObjectLike(_.noop);
// => false
_.isObjectLike(null);
// => false
Checks if value
is a safe integer. An integer is safe if it's an IEEE-754
double precision number which isn't the result of a rounded unsafe integer.
Note: This method is based on Number.isSafeInteger
.
The value to check.
Returns true
if value
is a safe integer, else false
.
_.isSafeInteger(3);
// => true
_.isSafeInteger(Number.MIN_VALUE);
// => false
_.isSafeInteger(Infinity);
// => false
_.isSafeInteger('3');
// => false
Converts value
to a finite number.
The value to convert.
Returns the converted number.
4.12.0
_.toFinite(3.2);
// => 3.2
_.toFinite(Number.MIN_VALUE);
// => 5e-324
_.toFinite(Infinity);
// => 1.7976931348623157e+308
_.toFinite('3.2');
// => 3.2
Converts value
to an integer.
Note: This function is loosely based on ToInteger
.
The value to convert.
Returns the converted integer.
_.toInteger(3);
// => 3
_.toInteger(Number.MIN_VALUE);
// => 0
_.toInteger(Infinity);
// => 1.7976931348623157e+308
_.toInteger('3');
// => 3
Converts value
to an integer suitable for use as the length of an
array-like object.
Note: This method is based on ToLength
.
The value to convert.
Returns the converted integer.
_.toLength(3);
// => 3
_.toLength(Number.MIN_VALUE);
// => 0
_.toLength(Infinity);
// => 4294967295
_.toLength('3');
// => 3
Converts value
to a safe integer. A safe integer can be compared and
represented correctly.
The value to convert.
Returns the converted integer.
_.toSafeInteger(3);
// => 3
_.toSafeInteger(Number.MIN_VALUE);
// => 0
_.toSafeInteger(Infinity);
// => 9007199254740991
_.toSafeInteger('3');
// => 3
Converts value
to a string if it's not one. An empty string is returned
for null
and undefined
values. The sign of -0
is preserved.
The value to process.
Returns the string.
_.toString(null);
// => ''
_.toString(-0);
// => '-0'
_.toString([1, 2, 3]);
// => '1,2,3'
This method is like _.max
except that it accepts iteratee
which is
invoked for each element in array
to generate the criterion by which
the value is ranked. The iteratee is invoked with one argument: (value).
Returns the maximum value.
var objects = [{ 'n': 1 }, { 'n': 2 }];
_.maxBy(objects, function(o) { return o.n; });
// => { 'n': 2 }
// using the `_.property` iteratee shorthand
_.maxBy(objects, 'n');
// => { 'n': 2 }
Computes the mean of the provided properties of the objects in the array
Returns the mean.
_.mean([{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }], 'n');
// => 5
This method is like _.min
except that it accepts iteratee
which is
invoked for each element in array
to generate the criterion by which
the value is ranked. The iteratee is invoked with one argument: (value).
Returns the minimum value.
var objects = [{ 'n': 1 }, { 'n': 2 }];
_.minBy(objects, function(o) { return o.a; });
// => { 'n': 1 }
// using the `_.property` iteratee shorthand
_.minBy(objects, 'n');
// => { 'n': 1 }
This method is like _.sum
except that it accepts iteratee
which is
invoked for each element in array
to generate the value to be summed.
The iteratee is invoked with one argument: (value).
Optional
iteratee: string | ((value) => number)The iteratee invoked per element.
Returns the sum.
var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
_.sumBy(objects, function(o) { return o.n; });
// => 20
// using the `_.property` iteratee shorthand
_.sumBy(objects, 'n');
// => 20
Clamps number
within the inclusive lower
and upper
bounds.
The number to clamp.
Optional
lower: numberThe lower bound.
The upper bound.
Returns the clamped number.
_.clamp(-10, -5, 5);
// => -5
_.clamp(10, -5, 5);
// => 5
Clamps `number` within the inclusive `lower` and `upper` bounds.
_.clamp(-10, -5, 5);
// => -5
_.clamp(10, -5, 5);
_.clamp
Assigns own enumerable properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
Note: This method mutates object
and is loosely based on
Object.assign
.
Returns object
.
function Foo() {
this.c = 3;
}
function Bar() {
this.e = 5;
}
Foo.prototype.d = 4;
Bar.prototype.f = 6;
_.assign({ 'a': 1 }, new Foo, new Bar);
// => { 'a': 1, 'c': 3, 'e': 5 }
_.assign
_.assign
_.assign
_.assign
Rest
...otherArgs: any[]_.assign
This method is like _.assign
except that it iterates over own and
inherited source properties.
Note: This method mutates object
.
Returns object
.
extend
function Foo() {
this.b = 2;
}
function Bar() {
this.d = 4;
}
Foo.prototype.c = 3;
Bar.prototype.e = 5;
_.assignIn({ 'a': 1 }, new Foo, new Bar);
// => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
_.assignIn
_.assignIn
_.assignIn
_.assignIn
Rest
...otherArgs: any[]_.assignIn
This method is like _.assignIn
except that it accepts customizer
which
is invoked to produce the assigned values. If customizer
returns undefined
assignment is handled by the method instead. The customizer
is invoked
with five arguments: (objValue, srcValue, key, object, source).
Note: This method mutates object
.
Returns object
.
extendWith
function customizer(objValue, srcValue) {
return _.isUndefined(objValue) ? srcValue : objValue;
}
var defaults = _.partialRight(_.assignInWith, customizer);
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }
_.assignInWith
_.assignInWith
_.assignInWith
_.assignInWith
Rest
...otherArgs: any[]_.assignInWith
This method 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 method instead. The customizer
is invoked
with five arguments: (objValue, srcValue, key, object, source).
Note: This method mutates object
.
Returns object
.
function customizer(objValue, srcValue) {
return _.isUndefined(objValue) ? srcValue : objValue;
}
var defaults = _.partialRight(_.assignWith, customizer);
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }
_.assignWith
_.assignWith
_.assignWith
_.assignWith
Rest
...otherArgs: any[]_.assignWith
Creates an array of function property names from own enumerable properties
of object
.
The object to inspect.
Returns the new array of property names.
function Foo() {
this.a = _.constant('a');
this.b = _.constant('b');
}
Foo.prototype.c = _.constant('c');
_.functions(new Foo);
// => ['a', 'b']
Creates an array of function property names from own and inherited
enumerable properties of object
.
The object to inspect.
Returns the new array of property names.
function Foo() {
this.a = _.constant('a');
this.b = _.constant('b');
}
Foo.prototype.c = _.constant('c');
_.functionsIn(new Foo);
// => ['a', 'b', 'c']
Checks if path
is a direct property of object
.
The object to query.
The path to check.
Returns true
if path
exists, else false
.
var object = { 'a': { 'b': { 'c': 3 } } };
var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
_.has(object, 'a');
// => true
_.has(object, 'a.b.c');
// => true
_.has(object, ['a', 'b', 'c']);
// => true
_.has(other, 'a');
// => false
Checks if path
is a direct or inherited property of object
.
The object to query.
The path to check.
Returns true
if path
exists, else false
.
var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
_.hasIn(object, 'a');
// => true
_.hasIn(object, 'a.b.c');
// => true
_.hasIn(object, ['a', 'b', 'c']);
// => true
_.hasIn(object, 'b');
// => false
Recursively merges own and inherited enumerable properties of source
objects into the destination object, skipping source properties that resolve
to undefined
. 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.
Note: This method mutates object
.
Returns object
.
var users = {
'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
};
var ages = {
'data': [{ 'age': 36 }, { 'age': 40 }]
};
_.merge(users, ages);
// => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
_.merge
_.merge
_.merge
Rest
...otherArgs: any[]_.merge
This method is like _.merge
except that it accepts customizer
which
is invoked to produce the merged values of the destination and source
properties. If customizer
returns undefined
merging is handled by the
method instead. The customizer
is invoked with seven arguments:
(objValue, srcValue, key, object, source, stack).
Returns object
.
function customizer(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}
var object = {
'fruits': ['apple'],
'vegetables': ['beet']
};
var other = {
'fruits': ['banana'],
'vegetables': ['carrot']
};
_.mergeWith(object, other, customizer);
// => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
_.mergeWith
_.mergeWith
_.mergeWith
Rest
...otherArgs: any[]_.mergeWith
The opposite of _.pick
; this method creates an object composed of the
own and inherited enumerable properties of object
that are not omitted.
Returns the new object.
var object = { 'a': 1, 'b': '2', 'c': 3 };
_.omit(object, ['a', 'c']);
// => { 'b': '2' }
_.omit
Rest
...paths: Many<PropertyName>[]_.omit
The opposite of _.pickBy
; this method creates an object composed of the
own and inherited enumerable properties of object
that predicate
doesn't return truthy for.
Returns the new object.
var object = { 'a': 1, 'b': '2', 'c': 3 };
_.omitBy(object, _.isNumber);
// => { 'b': '2' }
_.omitBy
_.omitBy
Creates an object composed of the picked object
properties.
Returns the new object.
var object = { 'a': 1, 'b': '2', 'c': 3 };
_.pick(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }
Rest
...props: Many<PropertyPath>[]_.pick
Creates an object composed of the object
properties predicate
returns
truthy for. The predicate is invoked with two arguments: (value, key).
Returns the new object.
var object = { 'a': 1, 'b': '2', 'c': 3 };
_.pickBy(object, _.isNumber);
// => { 'a': 1, 'c': 3 }
_.pickBy
_.pickBy
_.pickBy
_.pickBy
This method is like _.update
except that it accepts customizer
which is
invoked to produce the objects of path
. If customizer
returns undefined
path creation is handled by the method instead. The customizer
is invoked
with three arguments: (nsValue, key, nsObject).
Note: This method mutates object
.
Returns object
.
4.6.0
var object = {};
_.updateWith(object, '[0][1]', _.constant('a'), Object);
// => { '0': { '1': 'a' } }
_.updateWith
The semantic version number.
Creates a function that invokes func with the this binding of thisArg and prepends any additional _.bind arguments to those provided to the bound function.
The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.
Note: Unlike native Function#bind this method does not set the "length" property of bound functions.
The function to bind.
The this binding of func.
The arguments to be partially applied.
Returns the new bound function.
Creates a function that invokes the method at object[key] and prepends any additional _.bindKey arguments to those provided to the bound function.
This method differs from _.bind by allowing bound functions to reference methods that may be redefined or don’t yet exist. See Peter Michaux’s article for more details.
The _.bindKey.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.
The object the method belongs to.
The key of the method.
The arguments to be partially applied.
Returns the new bound function.
Optional
iteratee: StringIterator<any>Optional
iteratee: StringIterator<any>_.forEach
Optional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
iteratee: StringIterator<any>Optional
iteratee: StringIterator<any>_.forEachRight
Optional
predicate: ((value, key, parentValue, context) => boolean | void | { Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
cloneOptional
condense?: booleanOptional
includeOptional
keepOptional
leavesOptional
onOptional
cloneOptional
keepOptional
skipOptional
onOptional
cloneOptional
keepOptional
skipOptional
onOptional
cloneOptional
keepOptional
skipOptional
pathOptional
replaceOptional
rootOptional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
root_.head
Optional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
options: { Optional
checkOptional
childrenOptional
includeOptional
leavesOptional
rootOptional
options: { Optional
checkOptional
childrenOptional
includeOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => any)Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => string | number)Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => any)Optional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootCreates a function that memoizes the result of func. If resolver is provided it determines the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with the this binding of the memoized function.
Returns the new memoizing function.
Optional
options: { Optional
checkOptional
cloneOptional
condense?: booleanOptional
keepOptional
onOptional
cloneOptional
keepOptional
skipOptional
onOptional
cloneOptional
keepOptional
skipOptional
replaceCreates a function that, when called, invokes func with any additional partial arguments prepended to those provided to the new function. This method is similar to _.bind except it does not alter the this binding.
The function to partially apply arguments to.
Arguments to be partially applied.
The new partially applied function.
This method is like _.partial except that partial arguments are appended to those provided to the new function.
The function to partially apply arguments to.
Arguments to be partially applied.
The new partially applied function.
Rest
...prefixes: string[]Optional
options: { Optional
checkOptional
childrenOptional
includeOptional
includeOptional
leavesOptional
pathOptional
rootOptional
options: { Optional
checkOptional
cloneOptional
condense?: booleanOptional
keepOptional
onOptional
cloneOptional
keepOptional
skipOptional
onOptional
cloneOptional
keepOptional
skipOptional
replaceOptional
callback: ((accumulator, value, key, parentValue, context) => any)Optional
accumulator: anyOptional
options: { Optional
callbackOptional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootOptional
callback: ((value, key, parentValue, context) => boolean | void)Optional
options: { Optional
checkOptional
childrenOptional
includeOptional
leavesOptional
pathOptional
rootBy default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby (ERB). Change the following template settings to use alternative delimiters.
The opposite of _.before; this method creates a function that invokes func once it’s called n or more times.
The number of calls before func is invoked.
The function to restrict.
Returns the new restricted function.
Creates a function that accepts up to n arguments ignoring any additional arguments.
The function to cap arguments for.
Rest
...args: any[]Optional
n: numberThe arity cap.
Returns the new function.
Rest
...args: any[]Creates an array of elements corresponding to the given keys, or indexes, of collection. Keys may be specified as individual arguments or as arrays of keys.
Returns the new array of picked elements.
_.at
Creates a function that invokes func, with the this binding and arguments of the created function, while it’s called less than n times. Subsequent calls to the created function return the result of the last func invocation.
The number of calls at which func is no longer invoked.
The function to restrict.
Returns the new restricted function.
Binds methods of an object to the object itself, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided all enumerable function properties, own and inherited, of object are bound.
Note: This method does not set the "length" property of bound functions.
The object to bind and assign the bound methods to.
Rest
...methodNames: Many<string>[]The object method names to bind, specified as individual method names or arrays of method names.
Returns object.
Creates a lodash object that wraps value with explicit method chaining enabled.
The value to wrap.
Returns the new lodash wrapper instance.
_.chain
_.chain
_.chain
_.chain
_.chain
_.chain
_.chain
Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the final chunk will be the remaining elements.
The array to process.
Optional
size: numberThe length of each chunk.
Returns the new array containing chunks.
Creates a shallow clone of value.
Note: This method is loosely based on the structured clone algorithm and supports cloning arrays, array buffers, booleans, date objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps.
The value to clone.
Returns the cloned value.
This method is like _.clone except that it accepts customizer which is invoked to produce the cloned value. If customizer returns undefined cloning is handled by the method instead.
Returns the cloned value.
_.cloneWith
_.cloneWith
Creates a function that invokes the predicate properties of source
with the corresponding
property values of a given object, returning true if all predicates return truthy, else false.
Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.
Note: This method is equivalent to _.conforms when source is partially applied.
Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The iteratee is invoked with one argument: (value).
Returns the composed aggregate object.
_.countBy
Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the debounced function return the result of the last func invocation.
Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the the debounced function is invoked more than once during the wait timeout.
See David Corbacho’s article for details over the differences between _.debounce and _.throttle.
The function to debounce.
The number of milliseconds to delay.
The options object.
Returns the new debounced function.
Optional
wait: numberOptional
options: DebounceSettingsChecks value
to determine whether a default value should be returned in
its place. The defaultValue
is returned if value
is NaN
, null
,
or undefined
.
Returns the resolved value.
_.defaultTo
Assigns own enumerable properties of source object(s) to the destination object for all destination properties that resolve to undefined. Once a property is set, additional values of the same property are ignored.
Note: This method mutates object.
The destination object.
_.defaults
_.defaults
_.defaults
_.defaults
Rest
...sources: any[]_.defaults
Defers invoking the func until the current call stack has cleared. Any additional arguments are provided to func when it’s invoked.
The function to defer.
Rest
...args: any[]Rest
...args: any[]The arguments to invoke the function with.
Returns the timer id.
Invokes func after wait milliseconds. Any additional arguments are provided to func when it’s invoked.
The function to delay.
Rest
...args: any[]The number of milliseconds to delay invocation.
Rest
...args: any[]The arguments to invoke the function with.
Returns the timer id.
Creates an array of array
values not included in the other provided arrays using SameValueZero for
equality comparisons. The order and references of result values are determined by the first array.
Returns the new array of filtered values.
This method is like _.difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument: (value).
Returns the new array of filtered values.
_.differenceBy
_.differenceBy
_.differenceBy
_.differenceBy
_.differenceBy
_.differenceBy
Checks if string ends with the given target string.
Optional
string: stringThe string to search.
Optional
target: stringThe string to search for.
Optional
position: numberThe position to search from.
Returns true if string ends with target, else false.
Converts the characters "&", "<", ">", '"', "'", and "`" in string to their corresponding HTML entities.
Note: No other characters are escaped. To escape additional characters use a third-party library like he.
Though the ">" character is escaped for symmetry, characters like ">" and "/" don’t need escaping in HTML and have no special meaning unless they're part of a tag or unquoted attribute value. See Mathias Bynens’s article (under "semi-related fun fact") for more details.
Backticks are escaped because in IE < 9, they can break out of attribute values or HTML comments. See #59, #102, #108, and #133 of the HTML5 Security Cheatsheet for more details.
When working with HTML you should always quote attribute values to reduce XSS vectors.
Optional
string: stringThe string to escape.
Returns the escaped string.
Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsey. The predicate is invoked with three arguments: (value, index|key, collection).
Returns true if all elements pass the predicate check, else false.
_.every
_.extend
_.extend
_.extend
_.extend
_.extend
Rest
...otherArgs: any[]_.extend
_.extendWith
_.extendWith
_.extendWith
_.extendWith
_.extendWith
Rest
...otherArgs: any[]_.extendWith
Fills elements of array with value from start up to, but not including, end.
Note: This method mutates array.
The array to fill.
The value to fill array with.
Returns array.
_.fill
_.fill
_.fill
Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).
The collection to iterate over.
Optional
predicate: StringIterator<boolean>The function invoked per iteration.
Returns the new filtered array.
_.filter
_.filter
_.filter
_.filter
Iterates over elements of collection, returning the first element predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).
Returns the matched element, else undefined.
_.find
_.find
_.find
This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
Returns the index of the found element, else -1.
This method is like _.find except that it returns the key of the first element predicate returns truthy for instead of the element itself.
Returns the key of the matched element, else undefined.
This method is like _.find except that it iterates over elements of a collection from right to left.
The found element, else undefined.
_.findLast
_.findLast
_.findLast
This method is like _.findIndex except that it iterates over elements of collection from right to left.
Returns the index of the found element, else -1.
This method is like _.findKey except that it iterates over elements of a collection in the opposite order.
Returns the key of the matched element, else undefined.
Creates an array of flattened values by running each element in collection through iteratee and concating its result to the other mapped values. The iteratee is invoked with three arguments: (value, index|key, collection).
Returns the new flattened array.
_.flatMap
_.flatMap
_.flatMap
_.flatMap
_.flatMap
Creates a function that returns the result of invoking the provided functions with the this binding of the created function, where each successive invocation is supplied the return value of the previous.
Returns the new function.
Rest
...args: A_.flow
_.flow
_.flow
_.flow
_.flow
_.flow
Rest
...func: Many<((...args) => any)>[]Rest
...args: any[]_.flow
This method is like _.flow except that it creates a function that invokes the provided functions from right to left.
Returns the new function.
_.flowRight
_.flowRight
_.flowRight
_.flowRight
_.flowRight
Rest
...func: Many<((...args) => any)>[]Rest
...args: any[]_.flowRight
Iterates over elements of collection invoking iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
Note: As with other "Collections" methods, objects with a "length" property are iterated like arrays. To avoid this behavior _.forIn or _.forOwn may be used for object iteration.
_.each
Optional
iteratee: StringIterator<any>_.forEach
_.forEach
_.forEach
_.forEach
Optional
iteratee: StringIterator<any>_.forEach
_.forEach
_.forEach
This method is like _.forEach except that it iterates over elements of collection from right to left.
_.eachRight
Optional
iteratee: StringIterator<any>_.forEachRight
_.forEachRight
_.forEachRight
_.forEachRight
Optional
iteratee: StringIterator<any>_.forEachRight
_.forEachRight
_.forEachRight
Iterates over own and inherited enumerable properties of an object invoking iteratee for each property. The iteratee is invoked with three arguments: (value, key, object). Iteratee functions may exit iteration early by explicitly returning false.
Returns object.
_.forIn
Iterates over own enumerable properties of an object invoking iteratee for each property. The iteratee is invoked with three arguments: (value, key, object). Iteratee functions may exit iteration early by explicitly returning false.
Returns object.
_.forOwn
This method is like _.forOwn except that it iterates over properties of object in the opposite order.
Returns object.
_.forOwnRight
Gets the property value at path of object. If the resolved value is undefined the defaultValue is used in its place.
Returns the resolved value.
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
_.get
Optional
defaultValue: any_.get
Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is an array of the elements responsible for generating the key. The iteratee is invoked with one argument: (value).
Returns the composed aggregate object.
_.groupBy
Checks if n is between start and up to but not including, end. If end is not specified it’s set to start with start then set to 0.
The number to check.
The start of the range.
Optional
end: numberThe end of the range.
Returns true if n is in the range, else false.
Checks if target is in collection using SameValueZero for equality comparisons. If fromIndex is negative, it’s used as the offset from the end of collection.
True if the target element is found, else false.
Creates an array of unique values that are included in all of the provided arrays using SameValueZero for equality comparisons.
Rest
...arrays: (undefined | null | List<T>)[]The arrays to inspect.
Returns the new array of shared values.
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 unless multiValue is true.
The object to invert.
Returns the new inverted object.
This method is like _.invert except that the inverted object is generated from the results of running each element of object through 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: (value).
Returns the new inverted object.
_.invertBy
Invokes the method named by methodName on each element in the collection returning an array of the results of each invoked method. Additional arguments will be provided to each invoked method. If methodName is a function it will be invoked for, and this bound to, each element in the collection.
The collection to iterate over.
The name of the method to invoke.
Rest
...args: any[]Arguments to invoke the method with.
_.invokeMap
Checks if value is classified as an Array object.
Optional
value: anyThe value to check.
Returns true if value is correctly classified, else false.
Optional
value: any_.isArray
Checks if value is empty. A value is considered empty unless it’s an arguments object, array, string, or jQuery-like collection with a length greater than 0 or an object with own enumerable properties.
Optional
value: TThe value to inspect.
Returns true if value is empty, else false.
Optional
value: anyChecks if value is classified as a Number primitive or object.
Note: To exclude Infinity, -Infinity, and NaN, which are classified as numbers, use the _.isFinite method.
Optional
value: anyThe value to check.
Returns true if value is correctly classified, else false.
Checks if value is a plain object, that is, an object created by the Object constructor or one with a [[Prototype]] of null.
Note: This method assumes objects created by the Object constructor have no inherited enumerable properties.
Optional
value: anyThe value to check.
Returns true if value is a plain object, else false.
Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is the last element responsible for generating the key. The iteratee function is invoked with one argument: (value).
Returns the composed aggregate object.
_.keyBy
This method is like _.indexOf except that it iterates over elements of array from right to left.
Returns the index of the matched value, else -1.
Creates an array of values by running each element in collection through iteratee. The iteratee is invoked with three arguments: (value, index|key, collection).
Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues, _.reject, and _.some.
The guarded methods are: ary, callback, chunk, clone, create, curry, curryRight, drop, dropRight, every, fill, flatten, invert, max, min, parseInt, slice, sortBy, take, takeRight, template, trim, trimLeft, trimRight, trunc, random, range, sample, some, sum, uniq, and words
Returns the new mapped array.
_.map
_.map
_.map
_.map
_.map
_.map
The opposite of _.mapValues; this method creates an object with the same values as object and keys generated by running each own enumerable property of object through iteratee.
Returns the new mapped object.
_.mapKeys
Creates an object with the same keys as object and values generated by running each own enumerable property of object through iteratee. The iteratee function is invoked with three arguments: (value, key, object).
Returns the new mapped object.
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
_.mapValues
Creates a function that performs a deep comparison between a given object and source, returning true if the given object has equivalent property values, else false.
Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and strings. Objects are compared by their own, not inherited, enumerable properties. For comparing a single own or inherited property value see _.matchesProperty.
The object of property values to match.
Returns the new function.
_.matches
Creates a function that compares the property value of path on a given object to value.
Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and strings. Objects are compared by their own, not inherited, enumerable properties.
The path of the property to get.
The value to match.
Returns the new function.
_.matchesProperty
Creates a function that invokes the method at path on a given object. Any additional arguments are provided to the invoked method.
The path of the method to invoke.
Rest
...args: any[]The arguments to invoke the method with.
Returns the new function.
The opposite of _.method; this method creates a function that invokes the method at a given path on object. Any additional arguments are provided to the invoked method.
The object to query.
Rest
...args: any[]The arguments to invoke the method with.
Returns the new function.
Adds all own enumerable function properties of a source object to the destination object. If object is a function then methods are added to its prototype as well.
Note: Use _.runInContext to create a pristine lodash function to avoid conflicts caused by modifying the original.
The destination object.
The object of functions to add.
Optional
options: MixinOptionsThe options object.
Returns object.
Optional
options: MixinOptions_.mixin
Creates a function that negates the result of the predicate func. The func predicate is invoked with the this binding and arguments of the created function.
The predicate to negate.
Rest
...args: TReturns the new function.
Rest
...args: TCreates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first call. The func is invoked with the this binding and arguments of the created function.
The function to restrict.
Returns the new restricted function.
Creates a function that invokes iteratees with the arguments provided to the created function and returns their results.
Rest
...iteratees: Many<((...args) => TResult)>[]The iteratees to invoke.
Returns the new function.
Creates a function that runs each argument through a corresponding transform function.
The function to wrap.
Rest
...args: any[]Rest
...transforms: Many<((...args) => any)>[]The functions to transform arguments, specified as individual functions or arrays of functions.
Returns the new function.
Rest
...args: any[]Creates a function that checks if all of the predicates return truthy when invoked with the arguments provided to the created function.
Returns the new function.
Rest
...predicates: Many<((...args) => boolean)>[]Rest
...args: T[]Creates a function that checks if any of the predicates return truthy when invoked with the arguments provided to the created function.
Returns the new function.
Rest
...predicates: Many<((...args) => boolean)>[]Rest
...args: T[]Pads string on the left and right sides if it’s shorter than length. Padding characters are truncated if they can’t be evenly divided by length.
Optional
string: stringThe string to pad.
Optional
length: numberThe padding length.
Optional
chars: stringThe string used as padding.
Returns the padded string.
Pads string on the right side if it’s shorter than length. Padding characters are truncated if they exceed length.
Optional
string: stringThe string to pad.
Optional
length: numberThe padding length.
Optional
chars: stringThe string used as padding.
Returns the padded string.
Pads string on the left side if it’s shorter than length. Padding characters are truncated if they exceed length.
Optional
string: stringThe string to pad.
Optional
length: numberThe padding length.
Optional
chars: stringThe string used as padding.
Returns the padded string.
Converts string to an integer of the specified radix. If radix is undefined or 0, a radix of 10 is used unless value is a hexadecimal, in which case a radix of 16 is used.
Note: This method aligns with the ES5 implementation of parseInt.
The string to convert.
Optional
radix: numberThe radix to interpret value by.
Returns the converted integer.
Creates an array of elements split into two groups, the first of which contains elements predicate returns truthy for, while the second of which contains elements predicate returns falsey for. The predicate is invoked with three arguments: (value, index|key, collection).
Returns the array of grouped elements.
_.partition
_.partition
The opposite of _.property; this method creates a function that returns the property value at a given path on object.
The object to query.
Returns the new function.
Removes elements from array corresponding to the given indexes and returns an array of the removed elements. Indexes may be specified as an array of indexes or as individual arguments.
Note: Unlike _.at, this method mutates array.
The array to modify.
Rest
...indexes: Many<number>[]The indexes of elements to remove, specified as individual indexes or arrays of indexes.
Returns the new array of removed elements.
Rest
...indexes: Many<number>[]_.pullAt
Produces a random number between min and max (inclusive). If only one argument is provided a number between 0 and the given number is returned. If floating is true, or either min or max are floats, a floating-point number is returned instead of an integer.
Optional
floating: booleanSpecify returning a floating-point number.
Returns the random number.
Optional
floating: boolean_.random
Optional
floating: boolean_.random
_.random
Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. If end is not specified it’s set to start with start then set to 0. If end is less than start a zero-length range is created unless a negative step is specified.
The start of the range.
Optional
end: numberThe end of the range.
Optional
step: numberThe value to increment or decrement by.
Returns a new range array.
_.range
Creates a function that invokes func with arguments arranged according to the specified indexes where the argument value at the first index is provided as the first argument, the argument value at the second index is provided as the second argument, and so on.
The function to rearrange arguments for.
Rest
...args: any[]Rest
...indexes: Many<number>[]The arranged argument indexes, specified as individual indexes or arrays of indexes.
Returns the new function.
Rest
...args: any[]Reduces a collection to a value which is the accumulated result of running each element in the collection through the callback, where each successive callback execution consumes the return value of the previous execution. If accumulator is not provided the first element of the collection will be used as the initial accumulator value. The callback is invoked with four arguments: (accumulator, value, index|key, collection).
Returns the accumulated value.
_.reduce
_.reduce
_.reduce
_.reduce
_.reduce
This method is like _.reduce except that it iterates over elements of a collection from right to left.
The accumulated value.
_.reduceRight
_.reduceRight
_.reduceRight
_.reduceRight
_.reduceRight
The opposite of _.filter; this method returns the elements of collection that predicate does not return truthy for.
The collection to iterate over.
Optional
predicate: StringIterator<boolean>The function invoked per iteration.
Returns the new filtered array.
_.reject
_.reject
Removes all elements from array that predicate returns truthy for and returns an array of the removed elements. The predicate is invoked with three arguments: (value, index, array).
Note: Unlike _.filter, this method mutates array.
Returns the new array of removed elements.
Replaces matches for pattern in string with replacement.
Note: This method is based on String#replace.
Returns the modified string.
_.replace
Creates a function that invokes func with the this binding of the created function and arguments from start and beyond provided as an array.
Note: This method is based on the rest parameter.
The function to apply a rest parameter to.
Rest
...args: any[]Optional
start: numberThe start position of the rest parameter.
Returns the new function.
Rest
...args: any[]Gets a random element from collection.
Returns the random element.
_.sample
_.sample
Gets n random elements at unique keys from collection up to the size of collection.
Returns the random elements.
Optional
n: number_.sampleSize
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. Use _.setWith to customize path creation.
The object to modify.
The path of the property to set.
The value to set.
Returns object.
_.set
This method is like _.set except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead. The customizer is invoked with three arguments: (nsValue, key, nsObject).
Returns object.
_.setWith
Creates an array of shuffled values, using a version of the Fisher-Yates shuffle.
The collection to shuffle.
Returns the new shuffled array.
_.shuffle
Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The predicate is invoked with three arguments: (value, index|key, collection).
Returns true if any element passes the predicate check, else false.
_.some
Splits string by separator.
Note: This method is based on String#split.
The string to split.
Optional
separator: string | RegExpThe separator pattern to split by.
Optional
limit: numberThe length to truncate results to.
Returns the new array of string segments.
_.split
Creates a function that invokes func with the this binding of the created function and an array of arguments much like Function#apply.
Note: This method is based on the spread operator.
Returns the new function.
Checks if string starts with the given target string.
Optional
string: stringThe string to search.
Optional
target: stringThe string to search for.
Optional
position: numberThe position to search from.
Returns true if string starts with target, else false.
This method invokes interceptor and returns value. The interceptor is invoked with one argument; (value). The purpose of this method is to "tap into" a method chain in order to perform operations on intermediate results within the chain.
Returns value.
Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data properties may be accessed as free variables in the template. If a setting object is provided it takes precedence over _.templateSettings values.
Note: In the development build _.template utilizes sourceURLs for easier debugging.
For more information on precompiling templates see lodash's custom builds documentation.
For more information on Chrome extension sandboxes see Chrome's extensions documentation.
Optional
string: stringThe template string.
Optional
options: TemplateOptionsThe options object.
Returns the compiled template function.
Creates a throttled function that only invokes func at most once per every wait milliseconds. The throttled function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the throttled function return the result of the last func call.
Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the the throttled function is invoked more than once during the wait timeout.
The function to throttle.
Optional
wait: numberThe number of milliseconds to throttle invocations to.
Optional
options: ThrottleSettingsThe options object.
Returns the new throttled function.
Invokes the iteratee function n times, returning an array of the results of each invocation. The iteratee is invoked with one argument; (index).
Returns the array of results.
_.times
An alternative to _.reduce; this method transforms object to a new accumulator object which is the result of running each of its own enumerable properties through iteratee, with each invocation potentially mutating the accumulator object. The iteratee is invoked with four arguments: (accumulator, value, key, object). Iteratee functions may exit iteration early by explicitly returning false.
Returns the accumulated value.
_.transform
_.transform
_.transform
_.transform
Removes leading and trailing whitespace or specified characters from string.
Optional
string: stringThe string to trim.
Optional
chars: stringThe characters to trim.
Returns the trimmed string.
_.trim
Removes trailing whitespace or specified characters from string.
Optional
string: stringThe string to trim.
Optional
chars: stringThe characters to trim.
Returns the trimmed string.
_.trimEnd
Removes leading whitespace or specified characters from string.
Optional
string: stringThe string to trim.
Optional
chars: stringThe characters to trim.
Returns the trimmed string.
_.trimStart
Truncates string if it’s longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "…".
Optional
string: stringThe string to truncate.
Optional
options: TruncateOptionsThe options object or maximum string length.
Returns the truncated string.
The inverse of _.escape; this method converts the HTML entities &, <, >, ", ', and ` in string to their corresponding characters.
Note: No other HTML entities are unescaped. To unescape additional HTML entities use a third-party library like he.
Optional
string: stringThe string to unescape.
Returns the unescaped string.
This method is like _.union
except that it accepts iteratee
which is
invoked for each element of each arrays
to generate the criterion by which
uniqueness is computed. The iteratee is invoked with one argument: (value).
Returns the new array of combined values.
_.unionBy
_.unionBy
_.unionBy
_.unionBy
This method is like _.unzip except that it accepts an iteratee to specify how regrouped values should be combined. The iteratee is invoked with four arguments: (accumulator, value, index, group).
Returns the new array of regrouped elements.
_.unzipWith
This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to customize path creation. The updater is invoked with one argument: (value).
The object to modify.
The path of the property to set.
The function to produce the updated value.
Returns object.
Creates an array of the own enumerable property values of object.
Returns an array of property values.
_.values
_.values
Splits string
into an array of its words.
Optional
string: stringThe string to inspect.
Optional
pattern: string | RegExpThe pattern to match words.
Returns the words of string
.
_.words
Creates a function that provides value to the wrapper function as its first argument. Any additional arguments provided to the function are appended to those provided to the wrapper function. The wrapper is invoked with the this binding of the created function.
Returns the new function.
Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
Returns the new array of grouped elements.
_.zip
_.zip
_.zip
Rest
...arrays: (undefined | null | List<T>)[]_.zip
This method is like _.fromPairs except that it accepts two arrays, one of property identifiers and one of corresponding values.
The property names.
The property values.
Returns the new object.
Optional
props: List<PropertyName>_.zipObject
This method is like _.zip except that it accepts an iteratee to specify how grouped values should be combined. The iteratee is invoked with four arguments: (accumulator, value, index, group).
Returns the new array of grouped elements.
_.zipWith
_.zipWith
_.zipWith
_.zipWith
_.zipWith
Creates a function that iterates over pairs
and invokes the corresponding
function of the first predicate to return truthy. The predicate-function
pairs are invoked with the this
binding and arguments of the created
function.
The predicate-function pairs.
Returns the new composite function.
4.0.0
var func = _.cond([
[_.matches({ 'a': 1 }), _.constant('matches A')],
[_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
[_.stubTrue, _.constant('no match')]
]);
func({ 'a': 1, 'b': 2 });
// => 'matches A'
func({ 'a': 0, 'b': 1 });
// => 'matches B'
func({ 'a': '1', 'b': '2' });
// => 'no match'
Creates a function that invokes func
with the arguments of the created
function. If func
is a property name the created callback returns the
property value for a given element. If func
is an object the created
callback returns true
for elements that contain the equivalent object properties, otherwise it returns false
.
Optional
func: TFunctionThe value to convert to a callback.
Returns the callback.
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
// create custom iteratee shorthands
_.iteratee = _.wrap(_.iteratee, function(callback, func) {
var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
return !p ? callback(func) : function(object) {
return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
};
});
_.filter(users, 'age > 36');
// => [{ 'user': 'fred', 'age': 40 }]
Rest
...args: any[]_.iteratee
This method is like _.range
except that it populates values in
descending order.
The start of the range.
Optional
end: numberThe end of the range.
Optional
step: numberThe value to increment or decrement by.
Returns the new array of numbers.
_.rangeRight(4);
// => [3, 2, 1, 0]
_.rangeRight(-4);
// => [-3, -2, -1, 0]
_.rangeRight(1, 5);
// => [4, 3, 2, 1]
_.rangeRight(0, 20, 5);
// => [15, 10, 5, 0]
_.rangeRight(0, -4, -1);
// => [-3, -2, -1, 0]
_.rangeRight(1, 4, 0);
// => [1, 1, 1]
_.rangeRight(0);
// => []
_.rangeRight
Converts value
to a property path array.
The value to convert.
Returns the new property path array.
_.toPath('a.b.c');
// => ['a', 'b', 'c']
_.toPath('a[0].b.c');
// => ['a', '0', 'b', 'c']
var path = ['a', 'b', 'c'],
newPath = _.toPath(path);
console.log(newPath);
// => ['a', 'b', 'c']
console.log(path === newPath);
// => false
Creates a lodash object which wraps value to enable implicit method chain sequences. Methods that operate on and return arrays, collections, and functions can be chained together. Methods that retrieve a single value or may return a primitive value will automatically end the chain sequence and return the unwrapped value. Otherwise, the value must be unwrapped with value().
Explicit chain sequences, which must be unwrapped with value(), may be enabled using _.chain.
The execution of chained methods is lazy, that is, it's deferred until value() is implicitly or explicitly called.
Lazy evaluation allows several methods to support shortcut fusion. Shortcut fusion is an optimization to merge iteratee calls; this avoids the creation of intermediate arrays and can greatly reduce the number of iteratee executions. Sections of a chain sequence qualify for shortcut fusion if the section is applied to an array and iteratees accept only one argument. The heuristic for whether a section qualifies for shortcut fusion is subject to change.
Chaining is supported in custom builds as long as the value() method is directly or indirectly included in the build.
In addition to lodash methods, wrappers have Array and String methods. The wrapper Array methods are: concat, join, pop, push, shift, sort, splice, and unshift. The wrapper String methods are: replace and split.
The wrapper methods that support shortcut fusion are: at, compact, drop, dropRight, dropWhile, filter, find, findLast, head, initial, last, map, reject, reverse, slice, tail, take, takeRight, takeRightWhile, takeWhile, and toArray
The chainable wrapper methods are: after, ary, assign, assignIn, assignInWith, assignWith, at, before, bind, bindAll, bindKey, castArray, chain, chunk, commit, compact, concat, conforms, constant, countBy, create, curry, debounce, defaults, defaultsDeep, defer, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, extend, extendWith, fill, filter, flatMap, flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, flip, flow, flowRight, fromPairs, functions, functionsIn, groupBy, initial, intersection, intersectionBy, intersectionWith, invert, invertBy, invokeMap, iteratee, keyBy, keys, keysIn, map, mapKeys, mapValues, matches, matchesProperty, memoize, merge, mergeWith, method, methodOf, mixin, negate, nthArg, omit, omitBy, once, orderBy, over, overArgs, overEvery, overSome, partial, partialRight, partition, pick, pickBy, plant, property, propertyOf, pull, pullAll, pullAllBy, pullAllWith, pullAt, push, range, rangeRight, rearg, reject, remove, rest, reverse, sampleSize, set, setWith, shuffle, slice, sort, sortBy, sortedUniq, sortedUniqBy, splice, spread, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, thru, toArray, toPairs, toPairsIn, toPath, toPlainObject, transform, unary, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unset, unshift, unzip, unzipWith, update, updateWith, values, valuesIn, without, wrap, xor, xorBy, xorWith, zip, zipObject, zipObjectDeep, and zipWith.
The wrapper methods that are not chainable by default are: add, attempt, camelCase, capitalize, ceil, clamp, clone, cloneDeep, cloneDeepWith, cloneWith, conformsTo, deburr, defaultTo, divide, each, eachRight, endsWith, eq, escape, escapeRegExp, every, find, findIndex, findKey, findLast, findLastIndex, findLastKey, first, floor, forEach, forEachRight, forIn, forInRight, forOwn, forOwnRight, get, gt, gte, has, hasIn, head, identity, includes, indexOf, inRange, invoke, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFinite, isFunction, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp, isSafeInteger, isSet, isString, isUndefined, isTypedArray, isWeakMap, isWeakSet, join, kebabCase, last, lastIndexOf, lowerCase, lowerFirst, lt, lte, max, maxBy, mean, meanBy, min, minBy, multiply, noConflict, noop, now, nth, pad, padEnd, padStart, parseInt, pop, random, reduce, reduceRight, repeat, result, round, runInContext, sample, shift, size, snakeCase, some, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, startCase, startsWith, stubArray, stubFalse, stubObject, stubString, stubTrue, subtract, sum, sumBy, template, times, toFinite, toInteger, toJSON, toLength, toLower, toNumber, toSafeInteger, toString, toUpper, trim, trimEnd, trimStart, truncate, unescape, uniqueId, upperCase, upperFirst, value, and words.