Youssef Youssef - 1 year ago 75
jQuery Question

Parse just one query string parameter into Javascript array

I have this query string

How can I parse just the
parameter value in a array with javascript or jquery ?

I want the array like this

['how', 'can', 'i', 'get', 'this']

Answer Source

Assuming that the order of your query strings aren't always going to be known and that you have to support finding 'q' anywhere;

// substring(1) to skip the '?' character
var queryStrings ='&');
var qArray;
for (var i = 0; i < queryStrings.length; i++) {
  if (queryStrings[i].substring(0, 2) === 'q=') {
    qArray = queryStrings[i].substring(2).split('+');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download