Home > JavaScript, Technical > split a string at every n-th character in javascript

split a string at every n-th character in javascript

September 27, 2011

Syntax:

String.match(/.{1,n}/g);

Command:

“testing”.match(/.{1,2}/g);

Output:

te st in g

Advertisements
Categories: JavaScript, Technical
%d bloggers like this: