Category: js

Deserialize query string to JSON object

query string arrays (such as┬átest=1&test=2&test=3&check=wow&such=doge). This is my implementation: function queryStringToJSON(qs) { qs = qs || location.search.slice(1); var pairs = qs.split('&'); var result = {}; pairs.forEach(function(p) { var pair = p.split('='); var key = pair[0]; var value = decodeURIComponent(pair[1] || ''); if( result[key] ) { if( Object.prototype.toString.call( result[key] ) === '[object Array]' ) { result[key].push( […]