嘗試搜索失敗。我需要使用while循環來添加「!!!」到字符串數組中每個元素的末尾。我嘗試了幾種不同的方式,其中最近的是:<JS>需要使用while循環添加「!!!」的函數到數組的字符串元素的末尾
var facts = ["He was the last Beatle to learn to drive", "He was never a vegetarian", "He was a choir boy and boy scout",
"He hated the sound of his own voice"];
function johnLennonFacts(facts) {
var newFacts=[];
var i = 0;
while (i < 4) {
newFacts[i] = facts[i] +="!!!";
i++;
}
return newFacts;
}
必須是所有的JS庫沒有我所知道的。我是新來的代碼(顯然)。我知道可能有更好的方法來做到這一點,但我必須使用while循環。提前致謝。
刪除=從+ =,它會工作 –
你需要更改初始陣列或創建新的? – RomanPerekhrest
'+ ='是一個賦值操作符。如果你只是串聯!!!只需使用'+'。 – scrappedcola