我有一个包含"..."的字符串在不同的地方. 和一个字符串数组,该字符串数组具有与"..."相同的字数.
我想要替换所有出现的"..."使用字符串数组中的单词.
let stringToReplace = "I want an ... that I get from the ..."
let stringArray = ["apple","shop"]
result = "I want an apple that I get from the shop"
我试过这个:
let result = stringToReplace;
for (let i = 0; i < stringArray.length; i++) {
let inloc = stringArray[i];
result = result.replace("...", inloc);
}
但这只会改变"……"的第一次出现.