Convert Url query string key/value Format Into Object


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * Will convert a url query string key=val&key=val format into an object
  3. *
  4. * @param string str Url query string
  5. * @return object
  6. */
  7.  
  8. my.explode_to_object = function(str) {
  9. var cArr = str.split('&');
  10. var cObj = {};
  11. var cLen = cArr.length;
  12. for(var cnt=0;cLen--;cnt++) {
  13. var cStr = new String(cArr[cnt]);
  14. var cElem = cStr.split('=');
  15. cObj[cElem[0]] = cElem[1];
  16. }
  17.  
  18. return cObj;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.