new URLSearchParams(params: string): URLSearchParams
Parameter | Type | Description |
params | string | Query string. |
Methodology | Return Type | Description |
void | Add the specified key-value pair as a search parameter. | |
void | Delete the specified key and its value from the search parameter list. | |
string[][] | Get all key-value pairs from the query parameter. | |
void | Traverse all key-value pairs from URLSearchParams via a callback function | |
null or string | Get the first value for the specified search parameter. | |
string[] | Get all values for the specified search parameter. | |
boolean | Check whether the search parameter for the key exists. | |
string[] | Get all key names in the search parameter. | |
void | Set a new search parameter, which will be overridden if the key-value already exists. | |
string | Get the string of search parameters that can be directly used in a URL. | |
string[] | Get all values in the search parameter. |
import url from 'pts/url';export default function() {const params = new url.URLSearchParams('key1=value1&key2=value2');// Call append.params.append('key3', 'value3');console.log(params.toString()); // key1=value1&key2=value2&key3=value3// Call delete.params.delete('key3');console.log(params.toString()); // key1=value1&key2=value2// Call entries.// key1, value1// key2, value2for(var pair of params.entries()) {console.log(pair[0]+ ', '+ pair[1]);}// Call forEach.// value1, key1, [object Object]// value2, key2, [object Object]params.forEach(function(value, key, searchParams) {console.log(value, ', ', key, ', ', searchParams);});// Call get.console.log(params.get('key1')); // value1console.log(params.get('key3')); // null// Call getAll.params.append('key1', 1);console.log(params.getAll('key1')); // value1,1// Call has.console.log(params.has('key1')); // trueconsole.log(params.has('key3')); // false// Call keys.console.log(params.keys()); // key1,key2// Call set.params.set('key3', 'value3');params.set('key1', 'value1');// key1, value1// key2, value2// key3, value3for(var pair of params.entries()) {console.log(pair[0]+ ', '+ pair[1]);}// Call toString.console.log(params.toString()); // key1=value1&key2=value2&key3=value3// Call values.console.log(params.values()); // value1,value2,value3}