Node.js URL.search API
网址搜索是节点内网址类的内置应用编程接口。JS 。 URL.search API 用于获取和设置 URL 的查询部分。
Syntax: url.search
url : It is an object created by URL constructor.
示例 1:(获取网址的查询字符串)
java 描述语言
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org/?articles=nodejs");
//Getting query string of above created URL_1 object
console.log(URL_1.search);
输出:
示例 2:(设置网址的查询字符串)
java 描述语言
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org");
//Setting query string for URL_1
URL_1.search = "articles=web_technologies";
console.log(URL_1.href);
//Getting query string after setting
console.log(URL_1.search);
输出:
版权属于:月萌API www.moonapi.com,转载请注明出处