The array.slice() method can extract a slice from the beginning, middle, or end of an array for whatever purposes you require, without changing the original array.

const chunkSize = 10;
for (let i = 0; i < array.length; i += chunkSize) {
    const chunk = array.slice(i, i + chunkSize);
    // do whatever
}

The last chunk may be smaller than chunkSize. For example when given an array of 12 elements the first chunk will have 10 elements, the second chunk only has 2.

Note that a chunkSize of 0 will cause an infinite loop.

Answer from Blazemonger on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ String โ€บ split
String.prototype.split() - JavaScript | MDN
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_split.asp
JavaScript String split() Method
The split() method splits a string into an array of substrings.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ split-an-array-into-chunks-in-javascript
Split an Array into Chunks in JavaScript - GeeksforGeeks
July 11, 2025 - It automatically divides the array, returning an array of these chunks, with the last chunk containing the remaining elements if the array can't be evenly split.
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ split-string-javascript
How to Split a String in JavaScript | Built In
Summary: The JavaScript split() method divides a string into an array of substrings using a specified delimiter. It can be used for tasks like parsing CSV data, extracting URL components or reversing strings, and supports an optional limit on ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-split-how-to-split-a-string-into-an-array-in-js
JavaScript Split โ€“ How to Split a String into an Array in JS
June 16, 2021 - Usually, we use a splitter that is part of the string we are trying to split. There could be cases where you may have passed a splitter that is not part of the string or doesn't match any part of it. In that case, the split() method returns an array with the entire string as an element.
๐ŸŒ
Go Make Things
gomakethings.com โ€บ how-to-split-an-array-in-two-or-more-with-vanilla-js
How to split an array in two (or more) with vanilla JS | Go Make Things
If we pass in 2 as an argument, Array.splice() will โ€œcutโ€ the array in two, starting with the item at index 2.
Find elsewhere
๐ŸŒ
DEV Community
dev.to โ€บ jrcharney โ€บ split-and-join-the-dichotomy-of-strings-and-arrays-2hb
Split and Join: The Dichotomy of Strings and Arrays - DEV Community
December 19, 2022 - It might have been written before by someone else, but I'd like to give my own interpretation. Strings and Arrays are like Yin and Yang. You use .split() to split an string into an array.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-best-way-to-split-an-array-in-JavaScript
What is the best way to split an array in JavaScript? - Quora
Answer (1 of 6): You split a string, join an array. Think of it as "splitting" a string into a list of pieces, "joining" a list of pieces into a string. [code js] var array = ['foo', 'bar', 'baz']; var string = 'foo bar baz'; string.split(' '); // ['foo', 'bar', 'baz'] array.join(','); // 'f...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ how can i split an array into multiple arrays based on a property?
r/learnjavascript on Reddit: how can I split an array into multiple arrays based on a property?
August 9, 2021 -

I have an array like this

[
    {id:1, category:'category 1'},
    {id:2, name:'category 2'},
    {id:3, name:'category 1'},
    {id:4, name:'category 3'},
]

I wanna convert that into an array like this

[
    [
        {id:1, category:'category 1'},
        {id:3, name:'category 1'},
    ],
    [
        {id:2, name:'category 2'},
    ],
    [
        {id:4, name:'category 3'},
    ]
]

I don't know in advance the number of categories, any ideas how to achieve this?

๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ examples โ€บ split-array
JavaScript Program to Split Array into Smaller Chunks
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to split array into smaller chunks function splitIntoChunk(arr, chunk) { for (i=0; i < arr.length; i += chunk) { let tempArray; tempArray = arr.slice(i, i + chunk); ...
๐ŸŒ
Plus2Net
plus2net.com โ€บ javascript_tutorial โ€บ array-split.php
Split() method to create array by breaking string using delimiterin in JavaScript
February 5, 2000 - You can learn web programming and use them in your applications"; var a1 = new Array(); a1=str.split(" ",3); /// display elements /// for (i=0;i<a1.length;i++) { document.write(a1[i] + "<br >"); } </script> The output is here ยท Welcome to plus2net. We can break any email address by using @ as delimiter to separate userid ( or name ) and the domain part. <script type="text/javascript"> var str="username@example.com"; var a1 = new Array(); a1=str.split("@"); document.write (a1[0] + "<br>" + a1[1]); </script> Output is here
๐ŸŒ
Tabnine
tabnine.com โ€บ home โ€บ how to use split in javascript
How to Use split in JavaScript - Tabnine
July 25, 2024 - The split() method takes a string and returns an array of strings, splitting the original string based upon a provided separator character. This can be useful when only a certain portion of a string is required.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ standard-library โ€บ String โ€บ split
JavaScript String split() - Divide String Into Array | Vultr Docs
November 11, 2024 - The JavaScript split() method is a versatile string function that divides a string into an ordered list of substrates by separating the strings into substrings.
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ library โ€บ string โ€บ split
JavaScript String split()
Become a certified JavaScript programmer. Try Programiz PRO! ... The split() method divides a string into a list of substrings and returns them as an array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ split-a-string-into-an-array-of-words-in-javascript
Split a String into an Array of Words in JavaScript - GeeksforGeeks
July 23, 2025 - This results in an array where each element represents a word from the original string. Using split() method with a chosen separator such as a space (' '). It offers a simple and versatile way to break a string into an array of distinct elements.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-string-split-method
JavaScript String split() Method - GeeksforGeeks
The JavaScript split() method is used to break a string into an array of substrings based on a given separator.
Published ย  December 27, 2017
๐ŸŒ
DEV Community
dev.to โ€บ domhabersack โ€บ how-to-split-arrays-into-equal-sized-chunks-198h
How to split arrays into equal-sized chunks - DEV Community
January 6, 2021 - JavaScript provides a way to split strings into arrays with split(). If we want to split arrays into... Tagged with javascript.
๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-split-a-string-by-spaces-in-javascript
How to split a string by spaces in JavaScript ยท CoreUI
September 23, 2025 - The split(' ') method divides the string at each space character, creating an array where each word becomes a separate element. In this example, 'hello world javascript'.split(' ') produces ['hello', 'world', 'javascript']. This method preserves ...