I want to create a Javascript switch based on the array that I am creating from the query string. I am not sure how to proceed.
Say I have an array like this:
var myArray = ("#general","#controlpanel","#database");
I want to create this ...
switch(target){ case "#general": $("#general").show(); $("#controlpanel, #database").hide(); break; case "#controlpanel": $("#controlpanel").show(); $("#general, #database").hide(); break; case "#database": $("#database").show(); $("#general, #controlpanel").hide(); break; }
myArray can contain any number of elements, so I want the switch to be created dynamically based on the length of the array. The default
case would always be the first option.
An array is created from location.href with a regex to extract only what I need.
Thanks a lot!
source share