toQueryString
1.6

toQueryString(obj) -> String

Turns an object into its URL-encoded query string representation.

This is a form of serialization, and is mostly useful to provide complex parameter sets for stuff such as objects in the Ajax namespace (e.g. Ajax.Request).

Undefined-value pairs will be serialized as if empty-valued. Array-valued pairs will get serialized with one name/value pair per array element. All values get URI-encoded using JavaScript’s native encodeURIComponent function.

The order of pairs in the serialized form is not guaranteed (and mostly irrelevant anyway), except for array-based parts, which are serialized in array order.

Examples

Object.toQueryString({ action: 'ship', order_id: 123, fees: ['f1', 'f2'], 'label': 'a demo' })
// -> 'action=ship=123=f1=f2=a%20demo'