Working with Arrays in Lodash
Lodash provides numerous utility functions for working with arrays. Here are some commonly used array methods:
Creates an array of elements split into groups the length of size
.
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
Creates an array with all falsey values removed.
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
Creates a duplicate-free version of an array.
_.uniq([2, 1, 2]);
// => [2, 1]
Previous: Introduction Next: Object Methods
Last updated 3 days ago