URL.search是Node.JS中URL類的內置應用程序編程接口(API)。 URL.search API用於獲取和設置URL的查詢部分。
Syntax:url.search url:It is an object created by URL constructor.
示例1 :(獲取URL的查詢字符串)
//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);
輸出:
?articles=nodejs
示例2 :(設置URL的查詢字符串)
//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);
輸出:
https://www.geeksforgeeks.org/?articles=web_technologies ?articles=web_technologies
相關用法
- Node.js URLSearchParams.set()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js URL.hostname用法及代碼示例
- Node.js URL.href用法及代碼示例
- Node.js URL.hash用法及代碼示例
- Node.js URL.host用法及代碼示例
- Node.js URL.password用法及代碼示例
注:本文由純淨天空篩選整理自AshishkrGoyal大神的英文原創作品 Node | URL.search API。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。