I want to use JavaScript to convert an object into a query string.
For example, I want to convert:
{
a: 'hello',
b: {
b1: 'my',
b2: 'friend',
b3: {
c: 90
}
}
}
to:
?a=hello&b%5Bb1%5D=my&b%5Bb2%5D=friend&b%5Bb3%5D%5Bc%5D=90
I have found quite a few answers to this here: Flatten a javascript object to pass as querystring , but they don't seem to deal with the issue of associative arrays (or objects within objects).
I found a good answer for JQuery which works fine by using jQuery.param
, but i would like an answer using either native JS or Underscore.js.
How can I do this?