我有一个数组,一个json响应' slImgList':
[
[1, 19054, "<img src="http://example.com/images/0/19054.jpg"/>"],
[2, 24269, "<img src="http://example.com/images/0/24269.jpg"/>"],
[3, 38777, "<img src="http://example.com/images/0/38777.jpg"/>"]
]
如何更换&#39; images / 0&#39;与&#39; images / 5&#39; ? homeListLength是数组的数量。
for (var i = 0; i < homeListLength; i++) {
slImgList[i][2].replace("images/0", "images/5")
}
我也尝试过类似的东西,但它不起作用。
for(var i = 0; i&lt; homeListLength; i ++){
for (var j = 0; j < homeListLength[i]; j++) {
imagesList = slImgList[j][2].replace("images/0", "images/5")
}
}
答案 0 :(得分:0)
你几乎拥有它:
for (var j = 0; j < homeListLength[i]; j++) {
imagesList = slImgList[j][2].replace("images/0", "images/5")
slImgList[j][2] = imagesList
}