javascript - 如何将文本添加到 Javascript 数组中的每个文本值?
问题描述
我在我的应用程序中收到来自后端的文本数组,我无法控制
大批
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++) {
}
我已经能够添加到文本的末尾,但不能添加到前面。
有没有一种简单的方法可以在字符串的开头添加一些自定义文本?
解决方案
使用.map
并连接您需要的内容:
const arr = ["/tms/open-attachment/121", "/tms/open-attachment/122"];
const result = arr.map(str => 'some text added here' + str);
console.log(result);