jQuery - Turn JavaScript Object into query string
The method to turn an object directly into a query string with jQuery is the param method:
var obj = { name: 'chris', id: 21 };
var queryString = $.param(obj);
// results in : 'name=chris&id=21'
Written by Chris Missal
Related protips
3 Responses
Not trying to be rude, but how is this a "pro tip"? All you did was pull a method from the jQuery docs and then linked to it?
@bluetidepro I suppose "pro tip" isn't always black and white. This just came out of a conversation and the answer wasn't easily found at first. When I realized how easy it was to do, I created the tip as mostly a reminder to myself. I figured others that didn't know about $.param might find it useful as well.
@ChrisMissal Fair enough! :)
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside