Can you please look at this function and tell me where the error is? Firebug says that “string is undefined” … Any help is appreciated.
(links is declared above, console.debug(string) shows a comma delimited string)
function adRotate() {
var id = Math.floor(Math.random()*links.length);
var string = links[id];
var item = string.split(',');
console.debug(item);
}
The code should work. If the console “shows a comma delimited string“, this should either be a string or an Array.
In case
adRotate(["one,link", "second,link,"])– links is anArray– you’d get:possible results:
["one","link"]or["second","link"]In case
adRotate("one link, and second")– links is aString– you’d get:possible results:
["o"],["n"],["e"],[" "], …,["k"],["",""](for the comma char),["i"], etc.