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


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


URL.username是Node.JS中URL類的內置應用程序編程接口(API)。 URL.username API用於獲取和設置URL的用戶名。

Syntax:url.username
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://ashish:ashish123@www.geeksforgeeks.org"); 
  
//Getting username of above created URL_1 object 
console.log(URL_1.username);

輸出:


ashish

示例2 :(設置URL的用戶名)

//Creating an URL_1 object with URL constructor. 
const URL_1 = new URL("https://ashish:ashish123@www.geeksforgeeks.org/geeks"); 
  
//Getting username of above created URL_1 object 
console.log("Before changing username URL is:") 
console.log(URL_1.href); 
console.log("username:"+ URL_1.username); 
  
//Setting URL_1 username to ashu 
URL_1.username = "ashu"; 
  
//Getting username after setting it to ashu 
console.log("After changing username URL is:") 
console.log(URL_1.href); 
console.log("username:"+ URL_1.username);

輸出:

Before changing username URL is:
https://ashish:ashish123@www.geeksforgeeks.org/geeks
username:ashish

After changing username URL is:
https://ashu:ashish123@www.geeksforgeeks.org/geeks
username:ashu


相關用法


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