split string every 4 characters javascript code example
Example 1: split every n character js
var str = 'abcdefghijkl';
console.log(str.match(/.{1,3}/g));
Example 2: js split string every n characters
foo.match(new RegExp('.{1,' + n + '}', 'g'));
Example 3: split a string every n characters javascript
console.log("abcd".match(/.{1,2}/g)); // ["ab", "cd"]