[whatwg] URL: URLQuery

Tab Atkins Jr. jackalmage at gmail.com
Sat Oct 13 14:14:16 PDT 2012

On Sat, Oct 13, 2012 at 1:39 PM, Mike Dierken <mike at dierken.com> wrote:
> Since a URL query string is not a strict map with only one value for a
> key, would the get/set operations allow for an array as well as an
> atomic value?

Yes.  Regardless of the getters vs get() discussion, I think there was
consensus on the *operation* of the get/set operations.

For the sake of this discussion, I'll assume we use the Map api.

When you call get(), you'll get a *single* value - the first of the
potentially multiple values - or null.
When you call getAll(), you'll get a (possibly empty) array of values.
When you call set(), if you pass an array it sets all the values,
otherwise it stringifies the value and sets it as the sole value for
that key.

In other words, given an initial query of "?a=1&a=2", you get the
following results:

query.get('a') => 1
query.get('b') => null
query.getAll('a') => [1,2]
query.getAll('b') => []
query.set('a',3) => "?a=3"
query.set('b', [4,5]) => "?a=3&b=4&b=5"
query.set('c', {'c':1}) => "?a=3&b=4&b=5&c=%5Bobject%20Object%5D"


More information about the whatwg mailing list