Youssef Youssef - 6 months ago 29
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']


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('+');