How to split a long array into smaller arrays with JavaScript?

Spread the love

To split a long array into smaller arrays with JavaScript, we use the chunk method.


For instance, we write

const chunks = _.chunk(["a", "b", "c", "d"], 2);

to call the chunk function to split the ["a", "b", "c", "d"] into chunks of 2 and return an array with the chunks.