tencent cloud

Performance Testing Service

Overview
Purchase Guide
Billing Overview
Pay-as-You-Go (postpaid)
Purchasing Channels
Payment Overdue
Refund Instructions
Quick Start
Operation Guide
Performance Testing in Simple Mode
Performance Testing in Script Mode
Performance Testing in JMeter Mode
Project Management
Scenario Management
Traffic Recording
Environment Management
Scheduled Performance Testing
Performance Testing Report
Access Control
Alarm Management
Tag Management
Error Code Manual
Practice Tutorial
Using Prometheus To Monitor Performance Testing Metrics
Using PTS to Playback Requests Recorded by GoReplay
API Documentation
History
Introduction
API Category
Making API Requests
PTS-related APIs
Data Types
Error Codes
JavaScript API List
Overview of JavaScript API List
pts/global
pts/http
pts
pts/dataset
pts/grpc
pts/jsonpath
pts/protobuf
pts/redis
pts/sql
pts/url
pts/util
pts/ws
pts/socketio
pts/socket
FAQs
Related Agreements
Service Level Agreement
Use Limits
Privacy Policy
Data Processing And Security Agreement

URLSearchParams Overview

PDF
Focus Mode
Font Size
Last updated: 2025-03-10 17:23:44
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.
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.

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
}


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback