This processes a query string into a map object for easier usage.
The query string can contain a ? or not.
The code will populate the map variable with key value pairs of the parameters.
If there is more than one of the same key, the function will populate an array in the map with the multiple values within it
Usage:
var query = '?some=string&of=query¶meters';
var queryMap = getQueryMap(query);
console.log(queryMap['some']); // 'string'
console.log(queryMap['of']); // 'query'
console.log(queryMap['parameters']); // ''
The queryMap
variable in the above will resolve to:
{
"some": "string",
"of": "query",
"parameters": ""
}
A common use case would be to send in the url parameters:
var queryMap = getQueryMap(window.location.search);