This works.
String.prototype.replaceAll = function(str1, str2, ignore) {
let flags = 'g';
if (ignore) {
flags += 'i';
}
if (Array.isArray(str1) && Array.isArray(str2)) {
let newStr = this;
str1.map((element, index) => {
if (str2[index]) {
newStr = newStr.replace(new RegExp(element, flags), str2[index]);
}
return newStr;
});
return newStr;
}
else {
return this.replace(new RegExp(str1, flags), str2);
}
}