console.log("abcd".match(/.{1,2}/g)); // ["ab", "cd"]
var str = 'abcdefghijkl';
console.log(str.match(/.{1,3}/g));
let chunks = [];
for (let i = 0, charsLength = str.length; i < charsLength; i += 3) {
chunks.push(str.substring(i, i + 3));
}
foo.match(new RegExp('.{1,' + n + '}', 'g'));