I have for loop which goes through the array with arguments. When next argument is "?", "&" or "||", it shouldn't add comma, however, it always adds. I couldn't understand why, here is the code:
var args = ["arg1","arg2","?","arg3"];
var query = "";
for (var i = 0; i < args.length; i++) {
switch (args[i]) {
case "?":
query += " where ";
break;
case "&":
query += " and ";
break;
case "||":
query += " or ";
break;
default:
if (args[i+1] != "?");
{
query += args[i] + ", ";
break;
}
query += args[i] + " ";
break;
}
}
document.write(query);
When I type this (this is splitted by " " and sent to array args):
arg1 arg2 ? arg3
It prints it like this:
arg1, arg2, where arg3, // while it should be arg1, arg2 where arg3,
Thanks for helping people, problem was caused by an extern script. And yes, I removed semicolon ;)
arg1, arg2, where arg3, // while it should be arg1, arg2 where arg3,?arg2beforewhereis not wanted apparently.toStringmethod adds the comma.if (args[i+1] != "?");oops!