I have a string that I need to split on a given index and then return both parts, seperated by a comma. For example:
string: 8211 = 8,211
98700 = 98,
function splitText(value, index) {
if (value.length < index) {return value;}
return [value.substring(0, index)].concat(splitText(value.substring(index), index));
}
console.log(splitText('this is a testing peace of text',10));
// ["this is a ", "testing pe", "ace of tex", "t"]
For those who want to split a text into array using the index.