js URLSearchParams retrieves the search in the connection


  • URLSearchParams.append()
    Insert a specified key/value pair as a new search parameter.
  • URLSearchParams.delete()
    Delete the specified search parameters and their corresponding values from the search parameter list.
  • URLSearchParams.entries()
    Returns an iterator that traverses all key/value pairs.
  • URLSearchParams.get()
    Gets the first value of the specified search parameter.
  • URLSearchParams.getAll()
    Gets all the values of the specified search parameter and returns an array.
  • URLSearchParams.has()
    Returns Boolean to determine whether this search parameter exists.
  • URLSearchParams.keys()
    Returns iterator. This object contains all key names for key/value pairs.
  • URLSearchParams.set()
    Set a new value for the search parameter. If there are more than one value, all other values will be deleted.
  • URLSearchParams.sort()
    Keyboard name sort.
  • URLSearchParams.toString()
    Returns a string of search parameters that can be used directly on the URL.
  • URLSearchParams.values()
    Returns iterator. This object contains all the values of key/value pairs.
var paramsString = "?q=URLUtils.searchParams&topic=api"
var searchParams = new URLSearchParams(paramsString);

for (let p of searchParams) {

searchParams.has("topic") === true; // true
searchParams.get("topic") === "api"; // true
searchParams.getAll("topic"); // ["api"]
searchParams.get("foo") === ""; // true
searchParams.append("topic", "webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=api&topic=webdev"
searchParams.set("topic", "More webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=More+webdev"
searchParams.toString(); // "q=URLUtils.searchParams"

// Of course, he can do the following.
var params1 = new URLSearchParams({a:1,b:3,c:4})

params1.toString()     // "a=1&b=3&c=4"
params1.append('m', 'qiphon') 
params1.toString()      // "a=1&b=3&c=4&m=qiphon"
params1.append('m', '{a:123,b:234}')
params1.toString()     // "a=1&b=3&c=4&m=qiphon&m=%7Ba%3A123%2Cb%3A234%7D"
params1.getAll('m')   // (2) ["qiphon", "{a:123,b:234}"]
params1.toString()    // "a=1&b=3&c=4&m=qiphon&m=%7Ba%3A123%2Cb%3A234%7D&d=test"
params1.toString()   // "a=1&b=3&c=4&d=test&m=qiphon&m=%7Ba%3A123%2Cb%3A234%7D"

Reference for this article

  1. mdn
  2. whatwg

Posted by Jason Batten on Wed, 09 Oct 2019 00:25:40 -0700