I would like to slice a javascript string into an array of strings of specified length (the lenght can vary), so I would like to have length parametr as a separete variable:
var length = 3;
var string = 'aaabbbcccddd';
var myArray = string.match(/(.{3})/g);
How to use length variable in match? Or any other solution similar to str_split in PHP.
My question is not a duplicate of: Split large string in n-size chunks in JavaScript cause I know how to slice, but the question is how to use variable in match.
I can't manage to do that Javascript Regex: How to put a variable inside a regular expression?