Javascript Get all parameters and values as an Array - Code-Tips.com - Web Development, Programming, SEO

Sunday, February 13, 2011

Javascript Get all parameters and values as an Array

This Javascript function extracts each parameter from the query string and returns a multi dimensional array containing the parameter names and values.

Array( Array(parameter_name1, parameter_value1) , Array(parameter_name2, parameter_value2) )



function getAllParameters()
{
   fullQString = window.location.search.substring(1);
   paramArray = fullQString.split("&");
   var finalArray = new Array();
   for (i=0;i<paramArray.length;i++)
   {
     currentParameter = paramArray[i].split("=");
     finalArray[i] = Array(currentParameter[0], currentParameter[1]);
   }
   
   return finalArray;
}


Next: Javascript Return the url of the current page with no query string parameters

Previous: Javascript Get the value of the specified Query String Parameter

Javascript Query String Manipulation (TOC)

0 comments:

Post a Comment

Understood
This website is using cookies. More details