當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js URL.search用法及代碼示例


URL.search是一個內置的應用程序編程接口(API)網址類別Node.JS
URL.searchAPI用於獲取和設置URL的查詢部分。

Syntax: url.search
url : It is an object created by URL constructor.

示例1:(獲取URL的查詢字符串)

javascript


//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:(設置URL的查詢字符串)

javascript


//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); 

輸出:


相關用法


注:本文由純淨天空篩選整理自AshishkrGoyal大神的英文原創作品 Node.js URL.search API。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。