亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何向 Javascript 數組中的每個文本值添加文本?

如何向 Javascript 數組中的每個文本值添加文本?

largeQ 2023-08-18 10:29:24
我在我的應用程序中收到來自我無法控制的后端的文本數組大批this.Array = ["/tms/open-attachment/121", "/tms/open-attachment/122"]我試圖在開頭添加“此處添加的一些文本”this.Array =  ["some text added here/tms/open-attachment/121", "some text added here/tms/open-attachment/122"]使用for (let m = 0; m <this.Array.length; m++) {  }我可以添加到文本的末尾,但不能添加到前面。有沒有一種簡單的方法可以將一些自定義文本添加到字符串的開頭?
查看完整描述

2 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

使用.map并連接您需要的內容:


const arr = ["/tms/open-attachment/121", "/tms/open-attachment/122"];

const result = arr.map(str => 'some text added here' + str);

console.log(result);


查看完整回答
反對 回復 2023-08-18
?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

如果你想使用傳統的 for 循環:

for?(let?i?=?0;?i?<?array.length;?i++)?{?
????array[i]?=?"some?text"?+?array[i];
}

或者,正如CertainPerformance所說,您可以使用Array.prototype.map():

array?=?array.map(str?=>?"some?text"?+?str)


查看完整回答
反對 回復 2023-08-18
  • 2 回答
  • 0 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號