Lodash utility library exported as ES6 modules for modern JavaScript applications with tree-shaking support.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive array utilities for creation, modification, and analysis including chunking, flattening, set operations, and element manipulation.
Functions for creating arrays from other arrays or splitting arrays into smaller parts.
/**
* Creates an array of elements split into groups the length of size
* @param {Array} array - The array to process
* @param {number} size - The length of each chunk
* @returns {Array} Returns the new array of chunks
*/
function chunk(array, size);
/**
* Creates an array with all falsy values removed
* @param {Array} array - The array to compact
* @returns {Array} Returns the new array of filtered values
*/
function compact(array);
/**
* Creates a new array concatenating array with any additional arrays and/or values
* @param {Array} array - The array to concatenate
* @param {...*} values - The values to concatenate
* @returns {Array} Returns the new concatenated array
*/
function concat(array, ...values);Set operations for comparing arrays and finding differences or common elements.
/**
* Creates an array of values not included in the other given arrays
* @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);
/**
* Like difference but accepts iteratee for element comparisons
* @param {Array} array - The array to inspect
* @param {...Array} values - The values to exclude
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new array of filtered values
*/
function differenceBy(array, ...values, iteratee);
/**
* Like difference but accepts comparator for element comparisons
* @param {Array} array - The array to inspect
* @param {...Array} values - The values to exclude
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns the new array of filtered values
*/
function differenceWith(array, ...values, comparator);
/**
* Creates an array of unique values present in all given arrays
* @param {...Array} arrays - The arrays to inspect
* @returns {Array} Returns the new array of intersecting values
*/
function intersection(...arrays);
/**
* Like intersection but accepts iteratee for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new array of intersecting values
*/
function intersectionBy(...arrays, iteratee);
/**
* Like intersection but accepts comparator for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns the new array of intersecting values
*/
function intersectionWith(...arrays, comparator);Functions for removing elements from the beginning or end of arrays.
/**
* Creates a slice of array with n elements dropped from the beginning
* @param {Array} array - The array to query
* @param {number} n - The number of elements to drop
* @returns {Array} Returns the slice of array
*/
function drop(array, n);
/**
* Creates a slice of array with n elements dropped from the end
* @param {Array} array - The array to query
* @param {number} n - The number of elements to drop
* @returns {Array} Returns the slice of array
*/
function dropRight(array, n);
/**
* Creates a slice of array excluding elements dropped from the beginning
* @param {Array} array - The array to query
* @param {Function} predicate - The function invoked per iteration
* @returns {Array} Returns the slice of array
*/
function dropWhile(array, predicate);
/**
* Creates a slice of array excluding elements dropped from the end
* @param {Array} array - The array to query
* @param {Function} predicate - The function invoked per iteration
* @returns {Array} Returns the slice of array
*/
function dropRightWhile(array, predicate);
/**
* Gets all but the last element of array
* @param {Array} array - The array to query
* @returns {Array} Returns the slice of array
*/
function initial(array);
/**
* Gets all but the first element of array
* @param {Array} array - The array to query
* @returns {Array} Returns the slice of array
*/
function tail(array);Functions for extracting elements from arrays.
/**
* Creates a slice of array with n elements taken from the beginning
* @param {Array} array - The array to query
* @param {number} n - The number of elements to take
* @returns {Array} Returns the slice of array
*/
function take(array, n);
/**
* Creates a slice of array with n elements taken from the end
* @param {Array} array - The array to query
* @param {number} n - The number of elements to take
* @returns {Array} Returns the slice of array
*/
function takeRight(array, n);
/**
* Creates a slice of array with elements taken from the beginning
* @param {Array} array - The array to query
* @param {Function} predicate - The function invoked per iteration
* @returns {Array} Returns the slice of array
*/
function takeWhile(array, predicate);
/**
* Creates a slice of array with elements taken from the end
* @param {Array} array - The array to query
* @param {Function} predicate - The function invoked per iteration
* @returns {Array} Returns the slice of array
*/
function takeRightWhile(array, predicate);Functions for flattening nested arrays to various depths.
/**
* Flattens array a single level deep
* @param {Array} array - The array to flatten
* @returns {Array} Returns the new flattened array
*/
function flatten(array);
/**
* Recursively flattens array
* @param {Array} array - The array to flatten
* @returns {Array} Returns the new flattened array
*/
function flattenDeep(array);
/**
* Recursively flattens array up to depth times
* @param {Array} array - The array to flatten
* @param {number} depth - The maximum recursion depth
* @returns {Array} Returns the new flattened array
*/
function flattenDepth(array, depth);Functions for accessing and finding elements within arrays.
/**
* Gets the first element of array
* @param {Array} array - The array to query
* @returns {*} Returns the first element of array
*/
function head(array);
/**
* Gets the first element of array (alias for head)
* @param {Array} array - The array to query
* @returns {*} Returns the first element of array
*/
function first(array);
/**
* Gets the last element of array
* @param {Array} array - The array to query
* @returns {*} Returns the last element of array
*/
function last(array);
/**
* Gets the element at index n of array
* @param {Array} array - The array to query
* @param {number} n - The index of the element to return
* @returns {*} Returns the nth element of array
*/
function nth(array, n);
/**
* Gets the index at which the first occurrence of value is found in array
* @param {Array} array - The array to inspect
* @param {*} value - The value to search for
* @param {number} fromIndex - The index to search from
* @returns {number} Returns the index of the matched value, else -1
*/
function indexOf(array, value, fromIndex);
/**
* Gets the index at which the last occurrence of value is found in array
* @param {Array} array - The array to inspect
* @param {*} value - The value to search for
* @param {number} fromIndex - The index to search from
* @returns {number} Returns the index of the matched value, else -1
*/
function lastIndexOf(array, value, fromIndex);
/**
* Returns the index of the first element predicate returns truthy for
* @param {Array} array - The array to inspect
* @param {Function} predicate - The function invoked per iteration
* @param {number} fromIndex - The index to search from
* @returns {number} Returns the index of the found element, else -1
*/
function findIndex(array, predicate, fromIndex);
/**
* Like findIndex but iterates over elements from right to left
* @param {Array} array - The array to inspect
* @param {Function} predicate - The function invoked per iteration
* @param {number} fromIndex - The index to search from
* @returns {number} Returns the index of the found element, else -1
*/
function findLastIndex(array, predicate, fromIndex);Functions for modifying arrays by adding, removing, or changing elements.
/**
* Fills elements of array with value from start up to, but not including, end
* @param {Array} array - The array to fill
* @param {*} value - The value to fill array with
* @param {number} start - The start position
* @param {number} end - The end position
* @returns {Array} Returns array
*/
function fill(array, value, start, end);
/**
* Removes all given values from array using SameValueZero
* @param {Array} array - The array to modify
* @param {...*} values - The values to remove
* @returns {Array} Returns array
*/
function pull(array, ...values);
/**
* Like pull but accepts an array of values to remove
* @param {Array} array - The array to modify
* @param {Array} values - The values to remove
* @returns {Array} Returns array
*/
function pullAll(array, values);
/**
* Like pullAll but accepts iteratee for element comparisons
* @param {Array} array - The array to modify
* @param {Array} values - The values to remove
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns array
*/
function pullAllBy(array, values, iteratee);
/**
* Like pullAll but accepts comparator for element comparisons
* @param {Array} array - The array to modify
* @param {Array} values - The values to remove
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns array
*/
function pullAllWith(array, values, comparator);
/**
* Removes elements from array corresponding to indexes and returns them
* @param {Array} array - The array to modify
* @param {...number} indexes - The indexes of elements to remove
* @returns {Array} Returns the new array of removed elements
*/
function pullAt(array, ...indexes);
/**
* Removes all elements from array that predicate returns truthy for
* @param {Array} array - The array to modify
* @param {Function} predicate - The function invoked per iteration
* @returns {Array} Returns the array of removed elements
*/
function remove(array, predicate);
/**
* Reverses array so that the first element becomes the last
* @param {Array} array - The array to modify
* @returns {Array} Returns array
*/
function reverse(array);Functions for creating subarrays and converting arrays to strings.
/**
* Creates a slice of array from start up to, but not including, end
* @param {Array} array - The array to slice
* @param {number} start - The start position
* @param {number} end - The end position
* @returns {Array} Returns the slice of array
*/
function slice(array, start, end);
/**
* Converts all elements in array into a string separated by separator
* @param {Array} array - The array to convert
* @param {string} separator - The element separator
* @returns {string} Returns the joined string
*/
function join(array, separator);Functions for combining arrays and removing duplicates.
/**
* Creates an array of unique values, in order, from all given arrays
* @param {...Array} arrays - The arrays to inspect
* @returns {Array} Returns the new array of combined values
*/
function union(...arrays);
/**
* Like union but accepts iteratee for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new array of combined values
*/
function unionBy(...arrays, iteratee);
/**
* Like union but accepts comparator for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns the new array of combined values
*/
function unionWith(...arrays, comparator);
/**
* Creates a duplicate-free version of an array
* @param {Array} array - The array to inspect
* @returns {Array} Returns the new duplicate free array
*/
function uniq(array);
/**
* Like uniq but accepts iteratee for element comparisons
* @param {Array} array - The array to inspect
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new duplicate free array
*/
function uniqBy(array, iteratee);
/**
* Like uniq but accepts comparator for element comparisons
* @param {Array} array - The array to inspect
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns the new duplicate free array
*/
function uniqWith(array, comparator);Functions for excluding values and finding symmetric differences.
/**
* Creates an array excluding all given values using SameValueZero
* @param {Array} array - The array to inspect
* @param {...*} values - The values to exclude
* @returns {Array} Returns the new array of filtered values
*/
function without(array, ...values);
/**
* Creates an array of unique values that is the symmetric difference
* @param {...Array} arrays - The arrays to inspect
* @returns {Array} Returns the new array of filtered values
*/
function xor(...arrays);
/**
* Like xor but accepts iteratee for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new array of filtered values
*/
function xorBy(...arrays, iteratee);
/**
* Like xor but accepts comparator for element comparisons
* @param {...Array} arrays - The arrays to inspect
* @param {Function} comparator - The comparator invoked per element
* @returns {Array} Returns the new array of filtered values
*/
function xorWith(...arrays, comparator);Specialized functions for working with sorted arrays.
/**
* Uses binary search to determine the lowest index at which value should be inserted
* @param {Array} array - The sorted array to inspect
* @param {*} value - The value to evaluate
* @returns {number} Returns the index at which value should be inserted
*/
function sortedIndex(array, value);
/**
* Like sortedIndex but accepts iteratee for value comparison
* @param {Array} array - The sorted array to inspect
* @param {*} value - The value to evaluate
* @param {Function} iteratee - The iteratee invoked per element
* @returns {number} Returns the index at which value should be inserted
*/
function sortedIndexBy(array, value, iteratee);
/**
* Like indexOf but for sorted arrays
* @param {Array} array - The array to inspect
* @param {*} value - The value to search for
* @returns {number} Returns the index of the matched value, else -1
*/
function sortedIndexOf(array, value);
/**
* Like sortedIndex but returns the highest index at which value should be inserted
* @param {Array} array - The sorted array to inspect
* @param {*} value - The value to evaluate
* @returns {number} Returns the index at which value should be inserted
*/
function sortedLastIndex(array, value);
/**
* Like sortedLastIndex but accepts iteratee for value comparison
* @param {Array} array - The sorted array to inspect
* @param {*} value - The value to evaluate
* @param {Function} iteratee - The iteratee invoked per element
* @returns {number} Returns the index at which value should be inserted
*/
function sortedLastIndexBy(array, value, iteratee);
/**
* Like lastIndexOf but for sorted arrays
* @param {Array} array - The array to inspect
* @param {*} value - The value to search for
* @returns {number} Returns the index of the matched value, else -1
*/
function sortedLastIndexOf(array, value);
/**
* Like uniq but for sorted arrays
* @param {Array} array - The array to inspect
* @returns {Array} Returns the new duplicate free array
*/
function sortedUniq(array);
/**
* Like uniqBy but for sorted arrays
* @param {Array} array - The array to inspect
* @param {Function} iteratee - The iteratee invoked per element
* @returns {Array} Returns the new duplicate free array
*/
function sortedUniqBy(array, iteratee);Functions for combining and separating arrays.
/**
* Creates an array of grouped elements
* @param {...Array} arrays - The arrays to process
* @returns {Array} Returns the new array of grouped elements
*/
function zip(...arrays);
/**
* Like zip but accepts an iteratee to specify how grouped values should be combined
* @param {...Array} arrays - The arrays to process
* @param {Function} iteratee - The function to combine grouped values
* @returns {Array} Returns the new array of grouped elements
*/
function zipWith(...arrays, iteratee);
/**
* Creates an object composed from arrays of property paths and values
* @param {Array} props - The property paths
* @param {Array} values - The property values
* @returns {Object} Returns the new object
*/
function zipObject(props, values);
/**
* Like zipObject but supports property paths
* @param {Array} paths - The property paths
* @param {Array} values - The property values
* @returns {Object} Returns the new object
*/
function zipObjectDeep(paths, values);
/**
* Creates an array of regrouped elements
* @param {Array} array - The array of grouped elements to process
* @returns {Array} Returns the new array of regrouped elements
*/
function unzip(array);
/**
* Like unzip but accepts an iteratee to specify how regrouped values should be combined
* @param {Array} array - The array of grouped elements to process
* @param {Function} iteratee - The function to combine regrouped values
* @returns {Array} Returns the new array of regrouped elements
*/
function unzipWith(array, iteratee);Functions for converting arrays to other data structures.
/**
* Creates an object composed from key-value pairs
* @param {Array} pairs - The key-value pairs
* @returns {Object} Returns the new object
*/
function fromPairs(pairs);import { chunk, compact, difference, flatten } from "lodash-es";
// Split array into chunks
const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
const chunks = chunk(numbers, 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]
// Remove falsy values
const mixed = [0, 1, false, 2, '', 3, null, 4, undefined, 5, NaN];
const truthy = compact(mixed); // [1, 2, 3, 4, 5]
// Find differences between arrays
const arr1 = [1, 2, 3, 4, 5];
const arr2 = [3, 4, 5, 6, 7];
const diff = difference(arr1, arr2); // [1, 2]
// Flatten nested arrays
const nested = [1, [2, [3, [4]], 5]];
const flat = flatten(nested); // [1, 2, [3, [4]], 5]
const deepFlat = flattenDeep(nested); // [1, 2, 3, 4, 5]import { findIndex, pull, without, uniq } from "lodash-es";
const users = [
{ name: "Alice", age: 25 },
{ name: "Bob", age: 30 },
{ name: "Charlie", age: 25 }
];
// Find index of first match
const index = findIndex(users, { age: 25 }); // 0
// Remove values from array (mutates original)
const nums = [1, 2, 3, 4, 5, 2, 3];
pull(nums, 2, 3); // nums is now [1, 4, 5]
// Create new array without values
const filtered = without([1, 2, 3, 4, 5], 2, 3); // [1, 4, 5]
// Remove duplicates
const duplicates = [1, 2, 2, 3, 3, 4];
const unique = uniq(duplicates); // [1, 2, 3, 4]