You can use this function, just go to your string and length, and it will return an array, for example:
var outputString = splitter(shortData['new'], 148);
Function:
function splitter(str, l){ var strs = []; while(str.length > l){ var pos = str.substring(0, l).lastIndexOf(' '); pos = pos <= 0 ? l : pos; strs.push(str.substring(0, pos)); var i = str.indexOf(' ', pos)+1; if(i < pos || i > pos+l) i = pos; str = str.substring(i); } strs.push(str); return strs; }
Usage example:
splitter("This is a string with several characters.\ 120 to be precise I want to split it into substrings of length twenty or less.", 20);
Outputs:
["This is a string","with several","characters. 120 to", "be precise I want","to split it into","substrings of", "length twenty or","less."]
source share