Sometimes, we want to split JavaScript array in chunks using Lodash.
In this article, we’ll look at how to split JavaScript array in chunks using Lodash.
How to split JavaScript array in chunks using Lodash?
To split JavaScript array in chunks using Lodash, we can use the chunk function.
For instance, we write
const data = [
"a1",
"a2",
"a3",
"a4",
"a5",
"a6",
"a7",
"a8",
"a9",
"a10",
"a11",
"a12",
"a13",
];
const chunks = _.chunk(data, 3);
console.log(chunks);
to call chunks with the data array and 3 to split the data array into array chunks of 3 and return the split array.
Conclusion
To split JavaScript array in chunks using Lodash, we can use the chunk function.