Convert URL’s query string into JavaScript object.
Please visit one of the links above!
q2o(query, evaluate = true, separator = '&');
<script src="q2o.min.js"></script>
<script>
var config = q2o('?foo=1&bar=2');
console.log(config); // {"foo":1,"bar":2}
console.log(config.foo); // 1
console.log(config.bar); // 2
</script>
A function called o2q
, to convert object into URL’s query string is available here.
o2q(object, separator = '&', deep = 1, includeFalseAndNullValue = false);
false
and null
will be ignored.<script src="o2q.min.js"></script>
<script>
var data = {
a: 'b',
c: 'd',
e: {
f: 'g',
h: 'i',
j: {
k: 'l',
m: 'n'
}
}
},
set_1 = o2q(data),
set_2 = o2q(data, '&', 2);
console.log(set_1); // ?a=b&c=d&e[f]=g&e[h]=i&e[j]={"k":"l","m":"n"}
console.log(set_2); // ?a=b&c=d&e[f]=g&e[h]=i&e[j][k]=l&e[j][m]=n
</script>