Packages

class URLSearchParams extends Object with StObject with Iterable[Tuple2[String, String]]

The URLSearchParams API provides read and write access to the query of aURL. The URLSearchParams class can also be used standalone with one of the four following constructors. The URLSearchParams class is also available on the global object.

The WHATWG URLSearchParams interface and the querystring module have similar purpose, but the purpose of the querystring module is more general, as it allows the customization of delimiter characters (& and =). On the other hand, this API is designed purely for URL query strings.

js const myURL = new URL('https://example.org/?abc=123'); console.log(myURL.searchParams.get('abc')); // Prints 123

myURL.searchParams.append('abc', 'xyz'); console.log(myURL.href); // Prints https://example.org/?abc=123&abc=xyz

myURL.searchParams.delete('abc'); myURL.searchParams.set('a', 'b'); console.log(myURL.href); // Prints https://example.org/?a=b

const newSearchParams = new URLSearchParams(myURL.searchParams); // The above is equivalent to // const newSearchParams = new URLSearchParams(myURL.search);

newSearchParams.append('a', 'c'); console.log(myURL.href); // Prints https://example.org/?a=b console.log(newSearchParams.toString()); // Prints a=b&a=c

// newSearchParams.toString() is implicitly called myURL.search = newSearchParams; console.log(myURL.href); // Prints https://example.org/?a=b&a=c newSearchParams.delete('a'); console.log(myURL.href); // Prints https://example.org/?a=b&a=c

Annotations
@JSType() @JSImport("url", "URLSearchParams") @native()
Since

v7.5.0, v6.13.0

Linear Supertypes
Iterable[Tuple2[String, String]], StObject, Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. URLSearchParams
  2. Iterable
  3. StObject
  4. Object
  5. Any
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new URLSearchParams(init: Iterable[Tuple2[String, String]])
  2. new URLSearchParams(init: Array[Tuple2[String, String]])
  3. new URLSearchParams(init: String)
  4. new URLSearchParams(init: Record[String, |[String, Array[String]]])
  5. new URLSearchParams(init: URLSearchParams)
  6. new URLSearchParams()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def append(name: String, value: String): Unit

    Append a new name-value pair to the query string.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  7. def delete(name: String): Unit

    Remove all name-value pairs whose name is name.

  8. def entries(): IterableIterator[Tuple2[String, String]]

    Returns an ES6 Iterator over each of the name-value pairs in the query.

    Returns an ES6 Iterator over each of the name-value pairs in the query. Each item of the iterator is a JavaScript Array. The first item of the Arrayis the name, the second item of the Array is the value.

    Alias for urlSearchParams[@@iterator]().

  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def forEach[TThis](callback: ThisFunction3[TThis, String, String, URLSearchParams.this.type, Unit], thisArg: TThis): Unit
  12. def forEach[TThis](callback: ThisFunction3[TThis, String, String, URLSearchParams.this.type, Unit]): Unit

    Iterates over each name-value pair in the query and invokes the given function.

    Iterates over each name-value pair in the query and invokes the given function.

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

  13. def get(name: String): |[String, Null]

    Returns the value of the first name-value pair whose name is name.

    Returns the value of the first name-value pair whose name is name. If there are no such pairs, null is returned.

    returns

    or null if there is no name-value pair with the given name.

  14. def getAll(name: String): Array[String]

    Returns the values of all name-value pairs whose name is name.

    Returns the values of all name-value pairs whose name is name. If there are no such pairs, an empty array is returned.

  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  16. def has(name: String): Boolean

    Returns true if there is at least one name-value pair whose name is name.

  17. def hasOwnProperty(v: String): Boolean
    Definition Classes
    Object
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def isPrototypeOf(v: Object): Boolean
    Definition Classes
    Object
  21. val iterator: Function0[Iterator[Tuple2[String, String]]]
    Definition Classes
    Iterable
    Annotations
    @JSName(js.Symbol.iterator)
  22. var iterator_URLSearchParams: Function0[IterableIterator[Tuple2[String, String]]]
    Annotations
    @JSName(js.Symbol.iterator)
  23. def keys(): IterableIterator[String]

    Returns an ES6 Iterator over the names of each name-value pair.

    Returns an ES6 Iterator over the names of each name-value pair.

    js const params = new URLSearchParams('foo=bar&#x26;foo=baz'); for (const name of params.keys()) { console.log(name); } // Prints: // foo // foo

  24. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  27. def propertyIsEnumerable(v: String): Boolean
    Definition Classes
    Object
  28. def set(name: String, value: String): Unit

    Sets the value in the URLSearchParams object associated with name tovalue.

    Sets the value in the URLSearchParams object associated with name tovalue. If there are any pre-existing name-value pairs whose names are name, set the first such pair's value to value and remove all others. If not, append the name-value pair to the query string.

    js const params = new URLSearchParams(); params.append('foo', 'bar'); params.append('foo', 'baz'); params.append('abc', 'def'); console.log(params.toString()); // Prints foo=bar&#x26;foo=baz&#x26;abc=def

    params.set('foo', 'def'); params.set('xyz', 'opq'); console.log(params.toString()); // Prints foo=def&#x26;abc=def&#x26;xyz=opq

  29. def sort(): Unit

    Sort all existing name-value pairs in-place by their names.

    Sort all existing name-value pairs in-place by their names. Sorting is done with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs with the same name is preserved.

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

    js 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

    Since

    v7.7.0, v6.13.0

  30. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  31. def toLocaleString(): String
    Definition Classes
    Object
  32. def toString(): String
    Definition Classes
    AnyRef → Any
  33. def valueOf(): Any
    Definition Classes
    Object
  34. def values(): IterableIterator[String]

    Returns an ES6 Iterator over the values of each name-value pair.

  35. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  36. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  37. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from Iterable[Tuple2[String, String]]

Inherited from StObject

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped