コードは機能するはずです。コンソールに「コンマ区切りの文字列」が表示されている場合、これは文字列または配列のいずれかである必要があります。
adRotate(["one,link", "second,link,"])
-リンクが-の場合、次のArray
ようになります。
function adRotate(links) {
var id = Math.floor(Math.random()*links.length); // valid index in links
var str = links[id]; // selects one of the links: str is a String
var item = str.split(','); // splits the string to an Array
console.debug(item); // logs the array
}
考えられる結果:["one","link"]
または["second","link"]
adRotate("one link, and second")
-リンクが-の場合、次のString
ようになります。
function adRotate(links) {
var id = Math.floor(Math.random()*links.length); // valid index in links
var str = links[id]; // selects one of the chars in the string: str is a String of length 1
var item = str.split(','); // splits the one-char-string to an Array
console.debug(item); // logs the array
}
考えられる結果: 、、、、、 ... ["o"]
、、(コンマ文字の場合 ) 、、["n"]
など 。["e"]
[" "]
["k"]
["",""]
["i"]