tencent cloud

All product documents
Tencent Cloud Observability Platform
URLSearchParams Overview
Last updated: 2025-03-11 20:21:24
URLSearchParams Overview
Last updated: 2025-03-11 20:21:24
url.URLSearchParams defines some useful methods for processing the query string of the URL.

Constructor

Create an object instance using new, as shown below:
new URLSearchParams(params: string): URLSearchParams

Parameters

Parameter
Type
Description
params
string
Query string.

Methodology

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.
entries()
string[][]
Get all key-value pairs from the query parameter.
void
Traverse all key-value pairs from URLSearchParams via a callback function
get(key)
null or string
Get the first value for the specified search parameter.
string[]
Get all values for the specified search parameter.
has()
boolean
Check whether the search parameter for the key exists.
keys()
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.
values()
string[]
Get all values in the search parameter.

Samples

Construct instances and perform operations:
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, value2
for(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')); // value1
console.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')); // true
console.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, value3
for(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
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon