I imagine this is really simple but I just seem unable to achieve it. I have this snippet…
var choice = location.href.split("?")[1].split("=")[1];
It works fine until ‘choice’ is empty, then it throws the following error….
TypeError: location.href.split(...)[1] is undefined
I understand this is because you cant call split on a variable that is undefined, my solution i think is to store the variable and then split it if full or ignore it if undefined.
Can someone help me do this?
Not super cool to do it like this, but if you expect only one parameter in query string you can do it like this:
You will get
choiceasundedfinedif it’s not set in query string.