我正在嘗試編寫一個函數,它將刪除JavaScript中的字符串列表中的所有元音。我知道如何用單個字符串來做到這一點,但是當我應用一個字符串數組時,我遇到了問題。我收到錯誤TypeError: strings.replace is not a function
。如何從JavaScript中的字符串列表中刪除元音
var strings = ["bongo drums", "guitar",
"flute", "double bass", "xylophone","piano"];
string = strings.replace(/[aeiou]/g, '');
console.log(string);
在裏面做一個for? –
字符串是一個數組不是一個單獨的字符串,你需要使用映射或迭代通過每個字符串來做到這一點 –
檢查此鏈接,它似乎突出你的問題:https://stackoverflow.com/questions/26742310/replace-characters -in-串陣列的JavaScript。 – Koshux