1function splitArrayIntoChunksOfLen(arr, len) {
2 var chunks = [], i = 0, n = arr.length;
3 while (i < n) {
4 chunks.push(arr.slice(i, i += len));
5 }
6 return chunks;
7}
8var alphabet=['a','b','c','d','e','f'];
9var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2); //split into chunks of two
1// Example array.
2let randomArray = [3, 5, 1, 5, 7,];
3// Create an empty array.
4let arrayOfArrays = [];
5
6function splitArray( array ) {
7 while (array.length > 0) {
8 let arrayElement = array.splice(0,1);
9 arrayOfArrays.push(arrayElement);
10 }
11 return arrayOfArrays;
12}
13
14// Call the function while passing in an array of your choice.
15splitArray(randomArray)
16// => [ [ 3 ], [ 5 ], [ 1 ], [ 5 ], [ 7 ] ]