DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

JavaScript GetVars Array

10.20.2007
| 4516 views |
  • submit to reddit
        Figure out which Get-Vars are defined using client side javascript regex:

function getvars(s){
// php preg_match would be as easy as: (/([^&?=])=[^&?=]/g)
  a = s.match(/[^&?=]*=[^&?=]*/g);
  r = new Array();
  for (i=0; i<a.length; i++) {
  	r[i] = a[i].match(/[^&?=]*/)[0];
  }
  return(r);
}
/* test */
alert(getvars(window.location.search));