.chunk(array, [size=1])

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.

Arguments

  1. array (Array): The array to process.
  2. [size=1] (number): The length of each chunk.

Returns

(Array): Returns the new array containing chunks.

Example

  1. _.chunk(['a', 'b', 'c', 'd'], 2);
  2. // => [['a', 'b'], ['c', 'd']]
  3. _.chunk(['a', 'b', 'c', 'd'], 3);
  4. // => [['a', 'b', 'c'], ['d']]

.compact(array)

Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.

Arguments

  1. array (Array): The array to compact.

Returns

(Array): Returns the new array of filtered values.

Example

  1. _.compact([0, 1, false, 2, '', 3]);
  2. // => [1, 2, 3]

.difference(array, [values])

Creates an array of unique array values not included in the other provided arrays using SameValueZero for equality comparisons.

Arguments

  1. array (Array): The array to inspect.
  2. [values] (…Array): The arrays of values to exclude.

Returns

(Array): Returns the new array of filtered values.

Example

  1. _.difference([1, 2, 3], [4, 2]);
  2. // => [1, 3]

.drop(array, [n=1])

Creates a slice of array with n elements dropped from the beginning.

Arguments

  1. array (Array): The array to query.
  2. [n=1] (number): The number of elements to drop.

Returns

(Array): Returns the slice of array.

Example

  1. _.drop([1, 2, 3]);
  2. // => [2, 3]
  3. _.drop([1, 2, 3], 2);
  4. // => [3]
  5. _.drop([1, 2, 3], 5);
  6. // => []
  7. _.drop([1, 2, 3], 0);
  8. // => [1, 2, 3]

.dropRight(array, [n=1])

Creates a slice of array with n elements dropped from the end.

Arguments

  1. array (Array): The array to query.
  2. [n=1] (number): The number of elements to drop.

Returns

(Array): Returns the slice of array.

Example

  1. _.dropRight([1, 2, 3]);
  2. // => [1, 2]
  3. _.dropRight([1, 2, 3], 2);
  4. // => [1]
  5. _.dropRight([1, 2, 3], 5);
  6. // => []
  7. _.dropRight([1, 2, 3], 0);
  8. // => [1, 2, 3]

.dropRightWhile(array, [predicate=_.identity], [thisArg])

Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that match the properties of the given object, else false.

Arguments

  1. array (Array): The array to query.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(Array): Returns the slice of array.

Example

  1. _.dropRightWhile([1, 2, 3], function(n) {
  2. return n > 1;
  3. });
  4. // => [1]
  5. var users = [
  6. { 'user': 'barney', 'active': true },
  7. { 'user': 'fred', 'active': false },
  8. { 'user': 'pebbles', 'active': false }
  9. ];
  10. // using the `_.matches` callback shorthand
  11. _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  12. // => ['barney', 'fred']
  13. // using the `_.matchesProperty` callback shorthand
  14. _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  15. // => ['barney']
  16. // using the `_.property` callback shorthand
  17. _.pluck(_.dropRightWhile(users, 'active'), 'user');
  18. // => ['barney', 'fred', 'pebbles']

.dropWhile(array, [predicate=_.identity], [thisArg])

Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The array to query.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(Array): Returns the slice of array.

Example

  1. _.dropWhile([1, 2, 3], function(n) {
  2. return n < 3;
  3. });
  4. // => [3]
  5. var users = [
  6. { 'user': 'barney', 'active': false },
  7. { 'user': 'fred', 'active': false },
  8. { 'user': 'pebbles', 'active': true }
  9. ];
  10. // using the `_.matches` callback shorthand
  11. _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  12. // => ['fred', 'pebbles']
  13. // using the `_.matchesProperty` callback shorthand
  14. _.pluck(_.dropWhile(users, 'active', false), 'user');
  15. // => ['pebbles']
  16. // using the `_.property` callback shorthand
  17. _.pluck(_.dropWhile(users, 'active'), 'user');
  18. // => ['barney', 'fred', 'pebbles']

.fill(array, value, [start=0], [end=array.length])

Fills elements of array with value from start up to, but not including, end.

Note: This method mutates array.

Arguments

  1. array (Array): The array to fill.
  2. value (*): The value to fill array with.
  3. [start=0] (number): The start position.
  4. [end=array.length] (number): The end position.

Returns

(Array): Returns array.

Example

  1. var array = [1, 2, 3];
  2. _.fill(array, 'a');
  3. console.log(array);
  4. // => ['a', 'a', 'a']
  5. _.fill(Array(3), 2);
  6. // => [2, 2, 2]
  7. _.fill([4, 6, 8], '*', 1, 2);
  8. // => [4, '*', 8]

.findIndex(array, [predicate=_.identity], [thisArg])

This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The array to search.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(number): Returns the index of the found element, else -1.

Example

  1. var users = [
  2. { 'user': 'barney', 'active': false },
  3. { 'user': 'fred', 'active': false },
  4. { 'user': 'pebbles', 'active': true }
  5. ];
  6. _.findIndex(users, function(chr) {
  7. return chr.user == 'barney';
  8. });
  9. // => 0
  10. // using the `_.matches` callback shorthand
  11. _.findIndex(users, { 'user': 'fred', 'active': false });
  12. // => 1
  13. // using the `_.matchesProperty` callback shorthand
  14. _.findIndex(users, 'active', false);
  15. // => 0
  16. // using the `_.property` callback shorthand
  17. _.findIndex(users, 'active');
  18. // => 2

.findLastIndex(array, [predicate=_.identity], [thisArg])

This method is like _.findIndex except that it iterates over elements of collection from right to left.

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The array to search.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(number): Returns the index of the found element, else -1.

Example

  1. var users = [
  2. { 'user': 'barney', 'active': true },
  3. { 'user': 'fred', 'active': false },
  4. { 'user': 'pebbles', 'active': false }
  5. ];
  6. _.findLastIndex(users, function(chr) {
  7. return chr.user == 'pebbles';
  8. });
  9. // => 2
  10. // using the `_.matches` callback shorthand
  11. _.findLastIndex(users, { 'user': 'barney', 'active': true });
  12. // => 0
  13. // using the `_.matchesProperty` callback shorthand
  14. _.findLastIndex(users, 'active', false);
  15. // => 2
  16. // using the `_.property` callback shorthand
  17. _.findLastIndex(users, 'active');
  18. // => 0

.first(array)

Gets the first element of array.

Aliases

_.head

Arguments

  1. array (Array): The array to query.

Returns

(*): Returns the first element of array.

Example

  1. _.first([1, 2, 3]);
  2. // => 1
  3. _.first([]);
  4. // => undefined

.flatten(array, [isDeep])

Flattens a nested array. If isDeep is true the array is recursively flattened, otherwise it’s only flattened a single level.

Arguments

  1. array (Array): The array to flatten.
  2. [isDeep] (boolean): Specify a deep flatten.

Returns

(Array): Returns the new flattened array.

Example

  1. _.flatten([1, [2, 3, [4]]]);
  2. // => [1, 2, 3, [4]]
  3. // using `isDeep`
  4. _.flatten([1, [2, 3, [4]]], true);
  5. // => [1, 2, 3, 4]

.flattenDeep(array)

Recursively flattens a nested array.

Arguments

  1. array (Array): The array to recursively flatten.

Returns

(Array): Returns the new flattened array.

Example

  1. _.flattenDeep([1, [2, 3, [4]]]);
  2. // => [1, 2, 3, 4]

.indexOf(array, value, [fromIndex=0])

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. If array is sorted providing true for fromIndex performs a faster binary search.

Arguments

  1. array (Array): The array to search.
  2. value (*): The value to search for.
  3. [fromIndex=0] (boolean|number): The index to search from or true to perform a binary search on a sorted array.

Returns

(number): Returns the index of the matched value, else -1.

Example

  1. _.indexOf([1, 2, 1, 2], 2);
  2. // => 1
  3. // using `fromIndex`
  4. _.indexOf([1, 2, 1, 2], 2, 2);
  5. // => 3
  6. // performing a binary search
  7. _.indexOf([1, 1, 2, 2], 2, true);
  8. // => 2

.initial(array)

Gets all but the last element of array.

Arguments

  1. array (Array): The array to query.

Returns

(Array): Returns the slice of array.

Example

  1. _.initial([1, 2, 3]);
  2. // => [1, 2]

.intersection([arrays])

Creates an array of unique values that are included in all of the provided arrays using SameValueZero for equality comparisons.

Arguments

  1. [arrays] (…Array): The arrays to inspect.

Returns

(Array): Returns the new array of shared values.

Example

  1. _.intersection([1, 2], [4, 2], [2, 1]);
  2. // => [2]

.last(array)

Gets the last element of array.

Arguments

  1. array (Array): The array to query.

Returns

(*): Returns the last element of array.

Example

  1. _.last([1, 2, 3]);
  2. // => 3

.lastIndexOf(array, value, [fromIndex=array.length-1])

This method is like _.indexOf except that it iterates over elements of array from right to left.

Arguments

  1. array (Array): The array to search.
  2. value (*): The value to search for.
  3. [fromIndex=array.length-1] (boolean|number): The index to search from or true to perform a binary search on a sorted array.

Returns

(number): Returns the index of the matched value, else -1.

Example

  1. _.lastIndexOf([1, 2, 1, 2], 2);
  2. // => 3
  3. // using `fromIndex`
  4. _.lastIndexOf([1, 2, 1, 2], 2, 2);
  5. // => 1
  6. // performing a binary search
  7. _.lastIndexOf([1, 1, 2, 2], 2, true);
  8. // => 3

.pull(array, [values])

Removes all provided values from array using SameValueZero for equality comparisons.

Note: Unlike _.without, this method mutates array.

Arguments

  1. array (Array): The array to modify.
  2. [values] (…*): The values to remove.

Returns

(Array): Returns array.

Example

  1. var array = [1, 2, 3, 1, 2, 3];
  2. _.pull(array, 2, 3);
  3. console.log(array);
  4. // => [1, 1]

.pullAt(array, [indexes])

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.

Arguments

  1. array (Array): The array to modify.
  2. [indexes] (…(number|number[]): The indexes of elements to remove, specified as individual indexes or arrays of indexes.

Returns

(Array): Returns the new array of removed elements.

Example

  1. var array = [5, 10, 15, 20];
  2. var evens = _.pullAt(array, 1, 3);
  3. console.log(array);
  4. // => [5, 15]
  5. console.log(evens);
  6. // => [10, 20]

.remove(array, [predicate=_.identity], [thisArg])

Removes all elements from array that predicate returns truthy for and returns an array of the removed elements. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Note: Unlike _.filter, this method mutates array.

Arguments

  1. array (Array): The array to modify.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(Array): Returns the new array of removed elements.

Example

  1. var array = [1, 2, 3, 4];
  2. var evens = _.remove(array, function(n) {
  3. return n % 2 == 0;
  4. });
  5. console.log(array);
  6. // => [1, 3]
  7. console.log(evens);
  8. // => [2, 4]

.rest(array)

Gets all but the first element of array.

Aliases

_.tail

Arguments

  1. array (Array): The array to query.

Returns

(Array): Returns the slice of array.

Example

  1. _.rest([1, 2, 3]);
  2. // => [2, 3]

.slice(array, [start=0], [end=array.length])

Creates a slice of array from start up to, but not including, end.

Note: This method is used instead of Array#slice to support node lists in IE < 9 and to ensure dense arrays are returned.

Arguments

  1. array (Array): The array to slice.
  2. [start=0] (number): The start position.
  3. [end=array.length] (number): The end position.

Returns

(Array): Returns the slice of array.

.sortedIndex(array, value, [iteratee=_.identity], [thisArg])

Uses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order. If an iteratee function is provided it’s invoked for value and each element of array to compute their sort ranking. The iteratee is bound to thisArg and invoked with one argument; (value).

If a property name is provided for iteratee the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for iteratee the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The sorted array to inspect.
  2. value (*): The value to evaluate.
  3. [iteratee=_.identity] (Function|Object|string): The function invoked per iteration.
  4. [thisArg] (*): The this binding of iteratee.

Returns

(number): Returns the index at which value should be inserted into array.

Example

  1. _.sortedIndex([30, 50], 40);
  2. // => 1
  3. _.sortedIndex([4, 4, 5, 5], 5);
  4. // => 2
  5. var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  6. // using an iteratee function
  7. _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  8. return this.data[word];
  9. }, dict);
  10. // => 1
  11. // using the `_.property` callback shorthand
  12. _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  13. // => 1

.sortedLastIndex(array, value, [iteratee=_.identity], [thisArg])

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.

Arguments

  1. array (Array): The sorted array to inspect.
  2. value (*): The value to evaluate.
  3. [iteratee=_.identity] (Function|Object|string): The function invoked per iteration.
  4. [thisArg] (*): The this binding of iteratee.

Returns

(number): Returns the index at which value should be inserted into array.

Example

  1. _.sortedLastIndex([4, 4, 5, 5], 5);
  2. // => 4

.take(array, [n=1])

Creates a slice of array with n elements taken from the beginning.

Arguments

  1. array (Array): The array to query.
  2. [n=1] (number): The number of elements to take.

Returns

(Array): Returns the slice of array.

Example

  1. _.take([1, 2, 3]);
  2. // => [1]
  3. _.take([1, 2, 3], 2);
  4. // => [1, 2]
  5. _.take([1, 2, 3], 5);
  6. // => [1, 2, 3]
  7. _.take([1, 2, 3], 0);
  8. // => []

.takeRight(array, [n=1])

Creates a slice of array with n elements taken from the end.

Arguments

  1. array (Array): The array to query.
  2. [n=1] (number): The number of elements to take.

Returns

(Array): Returns the slice of array.

Example

  1. _.takeRight([1, 2, 3]);
  2. // => [3]
  3. _.takeRight([1, 2, 3], 2);
  4. // => [2, 3]
  5. _.takeRight([1, 2, 3], 5);
  6. // => [1, 2, 3]
  7. _.takeRight([1, 2, 3], 0);
  8. // => []

.takeRightWhile(array, [predicate=_.identity], [thisArg])

Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The array to query.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(Array): Returns the slice of array.

Example

  1. _.takeRightWhile([1, 2, 3], function(n) {
  2. return n > 1;
  3. });
  4. // => [2, 3]
  5. var users = [
  6. { 'user': 'barney', 'active': true },
  7. { 'user': 'fred', 'active': false },
  8. { 'user': 'pebbles', 'active': false }
  9. ];
  10. // using the `_.matches` callback shorthand
  11. _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  12. // => ['pebbles']
  13. // using the `_.matchesProperty` callback shorthand
  14. _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  15. // => ['fred', 'pebbles']
  16. // using the `_.property` callback shorthand
  17. _.pluck(_.takeRightWhile(users, 'active'), 'user');
  18. // => []

.takeWhile(array, [predicate=_.identity], [thisArg])

Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for predicate the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for predicate the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Arguments

  1. array (Array): The array to query.
  2. [predicate=_.identity] (Function|Object|string): The function invoked per iteration.
  3. [thisArg] (*): The this binding of predicate.

Returns

(Array): Returns the slice of array.

Example

  1. _.takeWhile([1, 2, 3], function(n) {
  2. return n < 3;
  3. });
  4. // => [1, 2]
  5. var users = [
  6. { 'user': 'barney', 'active': false },
  7. { 'user': 'fred', 'active': false},
  8. { 'user': 'pebbles', 'active': true }
  9. ];
  10. // using the `_.matches` callback shorthand
  11. _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  12. // => ['barney']
  13. // using the `_.matchesProperty` callback shorthand
  14. _.pluck(_.takeWhile(users, 'active', false), 'user');
  15. // => ['barney', 'fred']
  16. // using the `_.property` callback shorthand
  17. _.pluck(_.takeWhile(users, 'active'), 'user');
  18. // => []

.union([arrays])

Creates an array of unique values, in order, from all of the provided arrays using SameValueZero for equality comparisons.

Arguments

  1. [arrays] (…Array): The arrays to inspect.

Returns

(Array): Returns the new array of combined values.

Example

  1. _.union([1, 2], [4, 2], [2, 1]);
  2. // => [1, 2, 4]

.uniq(array, [isSorted], [iteratee], [thisArg])

Creates a duplicate-free version of an array, using SameValueZero for equality comparisons, in which only the first occurence of each element is kept. Providing true for isSorted performs a faster search algorithm for sorted arrays. If an iteratee function is provided it’s invoked for each element in the array to generate the criterion by which uniqueness is computed. The iteratee is bound to thisArg and invoked with three arguments: (value, index, array).

If a property name is provided for iteratee the created _.property style callback returns the property value of the given element.

If a value is also provided for thisArg the created _.matchesProperty style callback returns true for elements that have a matching property value, else false.

If an object is provided for iteratee the created _.matches style callback returns true for elements that have the properties of the given object, else false.

Aliases

_.unique

Arguments

  1. array (Array): The array to inspect.
  2. [isSorted] (boolean): Specify the array is sorted.
  3. [iteratee] (Function|Object|string): The function invoked per iteration.
  4. [thisArg] (*): The this binding of iteratee.

Returns

(Array): Returns the new duplicate-value-free array.

Example

  1. _.uniq([2, 1, 2]);
  2. // => [2, 1]
  3. // using `isSorted`
  4. _.uniq([1, 1, 2], true);
  5. // => [1, 2]
  6. // using an iteratee function
  7. _.uniq([1, 2.5, 1.5, 2], function(n) {
  8. return this.floor(n);
  9. }, Math);
  10. // => [1, 2.5]
  11. // using the `_.property` callback shorthand
  12. _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  13. // => [{ 'x': 1 }, { 'x': 2 }]

.unzip(array)

This method is like _.zip except that it accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.

Arguments

  1. array (Array): The array of grouped elements to process.

Returns

(Array): Returns the new array of regrouped elements.

Example

  1. var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  2. // => [['fred', 30, true], ['barney', 40, false]]
  3. _.unzip(zipped);
  4. // => [['fred', 'barney'], [30, 40], [true, false]]

.unzipWith(array, [iteratee], [thisArg])

This method is like _.unzip except that it accepts an iteratee to specify how regrouped values should be combined. The iteratee is bound to thisArg and invoked with four arguments: (accumulator, value, index, group).

Arguments

  1. array (Array): The array of grouped elements to process.
  2. [iteratee] (Function): The function to combine regrouped values.
  3. [thisArg] (*): The this binding of iteratee.

Returns

(Array): Returns the new array of regrouped elements.

Example

  1. var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  2. // => [[1, 10, 100], [2, 20, 200]]
  3. _.unzipWith(zipped, _.add);
  4. // => [3, 30, 300]

.without(array, [values])

Creates an array excluding all provided values using SameValueZero for equality comparisons.

Arguments

  1. array (Array): The array to filter.
  2. [values] (…*): The values to exclude.

Returns

(Array): Returns the new array of filtered values.

Example

  1. _.without([1, 2, 1, 3], 1, 2);
  2. // => [3]

.xor([arrays])

Creates an array of unique values that is the symmetric difference of the provided arrays.

Arguments

  1. [arrays] (…Array): The arrays to inspect.

Returns

(Array): Returns the new array of values.

Example

  1. _.xor([1, 2], [4, 2]);
  2. // => [1, 4]

.zip([arrays])

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.

Arguments

  1. [arrays] (…Array): The arrays to process.

Returns

(Array): Returns the new array of grouped elements.

Example

  1. _.zip(['fred', 'barney'], [30, 40], [true, false]);
  2. // => [['fred', 30, true], ['barney', 40, false]]

.zipObject(props, [values=[]])

The inverse of _.pairs; this method returns an object composed from arrays of property names and values. Provide either a single two dimensional array, e.g. [[key1, value1], [key2, value2]] or two arrays, one of property names and one of corresponding values.

Aliases

_.object

Arguments

  1. props (Array): The property names.
  2. [values=[]] (Array): The property values.

Returns

(Object): Returns the new object.

Example

  1. _.zipObject([['fred', 30], ['barney', 40]]);
  2. // => { 'fred': 30, 'barney': 40 }
  3. _.zipObject(['fred', 'barney'], [30, 40]);
  4. // => { 'fred': 30, 'barney': 40 }

.zipWith([arrays], [iteratee], [thisArg])

This method is like _.zip except that it accepts an iteratee to specify how grouped values should be combined. The iteratee is bound to thisArg and invoked with four arguments: (accumulator, value, index, group).

Arguments

  1. [arrays] (…Array): The arrays to process.
  2. [iteratee] (Function): The function to combine grouped values.
  3. [thisArg] (*): The this binding of iteratee.

Returns

(Array): Returns the new array of grouped elements.

Example

  1. _.zipWith([1, 2], [10, 20], [100, 200], _.add);
  2. // => [111, 222]