0 Tk

Array Methods

Working with Arrays in Lodash

Lodash provides numerous utility functions for working with arrays. Here are some commonly used array methods:

_.chunk(array, [size=1])

Creates an array of elements split into groups the length of size.

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

_.compact(array)

Creates an array with all falsey values removed.

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

_.uniq(array)

Creates a duplicate-free version of an array.

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

Previous: Introduction Next: Object Methods

Last updated 3 days ago