Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
Just another way (no recursive object):
You can also achieve this by using simple JavaScript.
Just use the following:
If you want to convert a nested object recursively and the object may or may not contain arrays (and the arrays may contain objects or arrays, etc), then the solution gets a little more complex. This is my attempt.
I've also added some options to choose if you want to record for each object member at what depth in the main object it sits, and to choose if you want to add a label to the members that come from converted arrays.
Ideally you should test if the thing parameter really receives an object or array.
ES6 SOLUTION FOR QUERY STRING ENCODING OF A JAVASCRIPT OBJECT
Single line to convert Object into Query String in case somebody need it again