Split array into two arrays

Solution 1:

var arr2 = ['a', 'b', 'c', 'd', 'e', 'f'];
arr = arr2.splice(0, arr2.indexOf('c'));

To remove 'c' from arr2:

arr2.splice(0,1);

arr contains the first two elements and arr2 contains the last three.

This makes some assumptions (like arr2 will always contain the 'point' at first assignment), so add some correctness checking for border cases as necessary.

Solution 2:

Sharing this convenience function that I ended up making after visiting this page.

function chunkArray(arr,n){
     var chunkLength = Math.max(arr.length/n ,1);
     var chunks = [];
     for (var i = 0; i < n; i++) {
         if(chunkLength*(i+1)<=arr.length)chunks.push(arr.slice(chunkLength*i, chunkLength*(i+1)));
     }
     return chunks; 
 }

Sample usage:

chunkArray([1,2,3,4,5,6],2);
//returns [[1,2,3],[4,5,6]]

chunkArray([1,2,3,4,5,6,7],2);
//returns [[1,2,3],[4,5,6,7]]

chunkArray([1,2,3,4,5,6],3);
//returns [[1,2],[3,4],[5,6]]

chunkArray([1,2,3,4,5,6,7,8],3);
//returns [[1,2],[3,4,5],[6,7,8]]

chunkArray([1,2,3,4,5,6,7,8],42);//over chunk
//returns [[1],[2],[3],[4],[5],[6],[7],[8]]