This doesn’t work but I can’t see why it wouldn’t? any help people? 🙂
params = qs.split("=", 2),
id = params[1];
if(id.indexOf("?") != -1){
id = id.split("?", 1);
}
basically I want to change the value of ‘ID’ if the IF statement is true, if not.. it skips it and the value Id remains the default.
Thanks
The result of
id = id.split("?", 1)is an array (of at most 1 item), but I think you want id to be a string. That would explain why id is not a string like you want.I agree with the other comments. Please show us the URL string you want to parse and tell us which piece you’re trying to get. Usually, you look for
?first, separate after that and then divide up variouskey=valuesections.If you had a URL like this:
Here’s a simple function that gets you all the query parameters into an object:
Working demo: http://jsfiddle.net/jfriend00/kNG3u/