var textToTranslate = "hello hello hello hello";
var words = ['hello'];
var translation = ['Hola']
var saveTranslation = textToTranslate;
for (var i = 0; i < words.length+1; i++){
saveTranslation = saveTranslation.replace(words[i], translation[i]);
}
console.log(saveTranslation);
其结果是“ hola hello hello hello”,但我正在尝试翻译所有出现的“ Hello”。得到“ Hola Hola Hola Hola”的结果 有任何想法吗?我不明白的是如何以这种形式使用数组
str = str.replace(/abc/g, '');