如何把链接串联成数组 [英] How to put link series into array
问题描述
我想打一系列的链接:
http://imgh.us/mk1.jpg
http://imgh.us/mk2.jpg
我使用一个for循环,使这一系列的环节,现在我希望把每一个第x值放入照片[I]
阵列。我尝试以下code,但它不工作。好像有
问题字符串concentation。我知道它的简单,但我有JS知之甚少。能否请您完成我的code?
我的code:
链接= 5;
VAR我;
变种照片=新的Array();
对于(i = 0; I<联系;我++){
照片[I] + ='的http:// IM gh.us/mk'+ I +名为.jpg;
}
您不应该使用在(空)数组分配一个新的变量时, + =
。< BR>
试试这个:
链接= 5;
变种照片=新的Array();
对于(VAR I = 0; I&LT;联系;我++){
照片[I] ='HTTP://imgh.us/mk'+ I +名为.jpg;
}
I want to make series of links:
http://imgh.us/mk1.jpg http://imgh.us/mk2.jpg
I am using a for loop to make this series of links, and now I want to put every x-th value into photos[i]
array. I try below code, but its not working. It seems like that there are
problems with string concentation. I know its simple but I have little knowledge of js. Can you please complete my code?
My code:
links =5;
var i;
var photos=new Array();
for(i=0;i<links;i++){
photos[i] +='http:// im gh.us/mk' +i+ ' .jpg ';
}
You shouldn't use +=
when assigning a new variable in a (empty) array.
Try this:
links = 5;
var photos = new Array();
for(var i =0; i < links; i++){
photos[i] ='http://imgh.us/mk' + i + ' .jpg';
}
这篇关于如何把链接串联成数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!