To split up a string, use: string.split
. If you want to split a string which is separated by a comma, use string.split(',')
.
When you want to split a string in parts of 10 characters, use:
var string = "15dsck3c rando mstring esjldf bjk";
var match = string.match(/[\S\s]{10}|[\S\s]{0,9}$/g); //{10} = 10 characters;
var listOfWords = Array.apply(null, match);
Splitting an array can be done by using the array.slice
method (which does not modify the array).
var arr = ["big", "small", "huge", "wall", "of", "text", "etc", "etc"];
var newList = [];
for(var i=0, len=arr.length; i<len; i+=10){
newList.push(arr.slice(i));
}
//newList is an array consisting of smaller arrays, eg
// [["big", <9 other elements>], [<10 elements>], ...]