instance method String#toQueryParams

View source on GitHub →

String#toQueryParams([separator = '&']) → Object

Parses a URI-like query string and returns an object composed of parameter/value pairs.

This method is realy targeted at parsing query strings (hence the default value of"&" for the separator argument).

For this reason, it does not consider anything that is either before a question mark (which signals the beginning of a query string) or beyond the hash symbol ("#"), and runs decodeURIComponent() on each parameter/value pair.

String#toQueryParams also aggregates the values of identical keys into an array of values.

Note that parameters which do not have a specified value will be set to undefined.

// -> {section: 'blog', id: '45'}
// -> {section: 'blog', id: '45'}
// -> {section: 'blog', id: '45'}
// -> {section: 'blog', tag: ['javascript', 'prototype', 'doc']}
// -> {tag: 'ruby on rails'}
// -> {id: '45', raw: undefined}

Alias of: String#parseQuery