Für einzigartig austauschbare Werte
String.prototype.replaceAll = function(search_array, replacement_array) {
//
var target = this;
//
search_array.forEach(function(substr, index) {
if (typeof replacement_array[index] != "undefined") {
target = target.replace(new RegExp(substr, 'g'), replacement_array[index])
}
});
//
return target;
};
// Use:
var replacedString = "This topic commented on :year. Talking :question.".replaceAll([':year', ':question'], ['2018', 'How to replace all occurrences of a string in JavaScript']);
//
console.log(replacedString);