Try the below code:
var foo = "foofaafoofaafoofaafoofaafoofaa";
console.log( foo.match(/.{1,3}/g) );
For nth position:
foo.match(new RegExp('.{1,' + n + '}', 'g'));
Try the below code:
var foo = "foofaafoofaafoofaafoofaafoofaa";
console.log( foo.match(/.{1,3}/g) );
For nth position:
foo.match(new RegExp('.{1,' + n + '}', 'g'));