let numbers = new Array('1','2','3');
let letters = new Array('a','b','c');
let length = numbers.length;
let str = 'abcdefgabcdefg';
for (let i=0; i<length; i++) {
let regex = new RegExp(numbers[i],'g');
str = str.replace(letters[i], regex);
}
alert(str);
The desired output is 123defg123defg. However, the actual output is /1/g/2/g/3/gdefgabcdefg.