Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Methods

[iterator]

append

  • append(name: string, value: string): void
  • Appends a specified key/value pair as a new search parameter.

    Parameters

    • name: string
    • value: string

    Returns void

delete

  • delete(name: string): void
  • Deletes the given search parameter, and its associated value, from the list of all search parameters.

    Parameters

    • name: string

    Returns void

entries

  • Returns an array of key, value pairs for every entry in the search params.

    Returns IterableIterator<[string, string]>

forEach

  • forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void
  • Iterates over each name-value pair in the query and invokes the given function.

    const myURL = new URL('https://example.org/?a=b&#x26;c=d');
    myURL.searchParams.forEach((value, name, searchParams) => {
      console.log(name, value, myURL.searchParams === searchParams);
    });
    // Prints:
    //   a b true
    //   c d true
    

    Parameters

    • callbackfn: (value: string, key: string, parent: URLSearchParams) => void
    • Optional thisArg: any

    Returns void

get

  • get(name: string): null | string
  • Returns the first value associated to the given search parameter.

    Parameters

    • name: string

    Returns null | string

getAll

  • getAll(name: string): string[]
  • Returns all the values association with a given search parameter.

    Parameters

    • name: string

    Returns string[]

has

  • has(name: string): boolean
  • Returns a Boolean indicating if such a search parameter exists.

    Parameters

    • name: string

    Returns boolean

keys

  • Returns a list of keys in the search params.

    Returns IterableIterator<string>

set

  • set(name: string, value: string): void
  • Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.

    Parameters

    • name: string
    • value: string

    Returns void

sort

  • sort(): void
  • Sort all existing name-value pairs in-place by their names. Sorting is done with a stable sorting algorithm, so relative order between name-value pairs with the same name is preserved.

    This method can be used, in particular, to increase cache hits.

    const params = new URLSearchParams('query[]=abc&#x26;type=search&#x26;query[]=123');
    params.sort();
    console.log(params.toString());
    // Prints query%5B%5D=abc&#x26;query%5B%5D=123&#x26;type=search
    

    Returns void

toString

  • toString(): string
  • Returns a string containing a query string suitable for use in a URL. Does not include the question mark.

    Returns string

values

  • Returns a list of values in the search params.

    Returns IterableIterator<string>