The complete modularized lodash v3.0.3 library exported as standalone npm packages for utility functions, collections, objects, arrays, and more.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Essential array manipulation utilities for transforming, filtering, and organizing data. These functions provide powerful ways to work with arrays while maintaining immutability principles.
Creates an array of elements split into groups the length of size.
/**
* Creates an array of elements split into groups the length of `size`.
* If `array` can't be split evenly, the final chunk will be the remaining elements.
*
* @param {Array} array The array to process.
* @param {number} [size=1] The length of each chunk.
* @returns {Array} Returns the new array containing chunks.
*/
function chunk(array, size);Usage Examples:
var chunk = require('lodash.chunk');
chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]Creates an array with all falsey values removed.
/**
* Creates an array with all falsey values removed. The values
* `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey.
*
* @param {Array} array The array to compact.
* @returns {Array} Returns the new array of filtered values.
*/
function compact(array);Usage Examples:
var compact = require('lodash.compact');
compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]Flattens array a single level deep.
/**
* Flattens `array` a single level deep.
*
* @param {Array} array The array to flatten.
* @returns {Array} Returns the new flattened array.
*/
function flatten(array);Usage Examples:
var flatten = require('lodash.flatten');
flatten([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]Recursively flattens array.
/**
* Recursively flattens `array`.
*
* @param {Array} array The array to flatten.
* @returns {Array} Returns the new flattened array.
*/
function flattenDeep(array);Usage Examples:
var flattenDeep = require('lodash.flattendeep');
flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]Creates a duplicate-free version of an array.
/**
* Creates a duplicate-free version of an array, using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons, in which only the first occurrence of each element
* is kept.
*
* @param {Array} array The array to inspect.
* @param {boolean} [isSorted] Specify the array is sorted.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new duplicate free array.
*/
function uniq(array, isSorted, iteratee, thisArg);Usage Examples:
var uniq = require('lodash.uniq');
uniq([2, 1, 2]);
// => [2, 1]
// Sort first for better performance
uniq([1, 2, 2, 3], true);
// => [1, 2, 3]
// Custom iteratee
uniq([2.1, 1.2, 2.3], function(n) { return Math.floor(n); });
// => [2.1, 1.2]Creates an array of array values not included in the other given arrays.
/**
* Creates an array of `array` values not included in the other given arrays
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @returns {Array} Returns the new array of filtered values.
*/
function difference(array, ...values);Usage Examples:
var difference = require('lodash.difference');
difference([1, 2, 3], [4, 2]);
// => [1, 3]
difference([1, 2, 3, 4, 5], [2, 4], [1]);
// => [3, 5]Creates an array of unique values that are included in all given arrays.
/**
* Creates an array of unique values that are included in all given arrays
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values.
*/
function intersection(...arrays);Usage Examples:
var intersection = require('lodash.intersection');
intersection([1, 2], [2, 3]);
// => [2]
intersection([1, 2, 3], [2, 3, 4], [2, 5]);
// => [2]Creates an array of unique values, in order, from all given arrays.
/**
* Creates an array of unique values, in order, from all given arrays using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons.
*
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of combined values.
*/
function union(...arrays);Usage Examples:
var union = require('lodash.union');
union([1, 2], [2, 3]);
// => [1, 2, 3]Creates a slice of array with n elements dropped from the beginning.
/**
* Creates a slice of `array` with `n` elements dropped from the beginning.
*
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.
* @returns {Array} Returns the slice of `array`.
*/
function drop(array, n);Usage Examples:
var drop = require('lodash.drop');
drop([1, 2, 3]);
// => [2, 3]
drop([1, 2, 3], 2);
// => [3]Creates a slice of array with n elements taken from the beginning.
/**
* Creates a slice of `array` with `n` elements taken from the beginning.
*
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.
* @returns {Array} Returns the slice of `array`.
*/
function take(array, n);Usage Examples:
var take = require('lodash.take');
take([1, 2, 3]);
// => [1]
take([1, 2, 3], 2);
// => [1, 2]Gets the index at which the first occurrence of value is found in array.
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-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.
*
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {boolean|number} [fromIndex=0] The index to search from or `true` to perform a binary search.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function indexOf(array, value, fromIndex);Usage Examples:
var indexOf = require('lodash.indexof');
indexOf([1, 2, 1, 2], 2);
// => 1
// Search from index
indexOf([1, 2, 1, 2], 2, 2);
// => 3
// Binary search on sorted array
indexOf([1, 1, 2, 2], 2, true);
// => 2Creates an array of grouped elements, the first of which contains the first elements of the given 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.
*
* @param {...Array} [arrays] The arrays to process.
* @returns {Array} Returns the new array of grouped elements.
*/
function zip(...arrays);Usage Examples:
var zip = require('lodash.zip');
zip(['fred', 'barney'], [30, 40], [true, false]);
// => [['fred', 30, true], ['barney', 40, false]]The array category also includes: dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, first, initial, last, lastIndexOf, pull, pullAt, remove, rest, slice, sortedIndex, sortedLastIndex, takeRight, takeRightWhile, takeWhile, unzip, without, xor, zipObject
Package Installation:
npm install lodash.chunk lodash.compact lodash.flatten lodash.flattendeep
npm install lodash.uniq lodash.difference lodash.intersection lodash.union
npm install lodash.drop lodash.take lodash.indexof lodash.zip