function splitText(txt, len = 10){ txt = txt.match(new RegExp(`.{${len}}`,'g')) txt = txt.map(el => el[0].toUpperCase() + el.slice(1)) return txt.join('\n') } alert(splitText('abcdefghijklmnop', 4))