URL.username 是 Node.JS 中 URL 类的内置应用程序编程接口 (API)。
URL.username API 用于获取和设置 URL 的用户名。
用法:
url.username
URL:它是由 URL 构造函数创建的对象。
示例1:(获取URL的用户名)
javascript
//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);
输出:
示例2:(设置URL的用户名)
javascript
//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);
输出:
相关用法
- Node.js URL.username用法及代码示例
- Node.js URL.toJSON()用法及代码示例
- Node.js URL.pathToFileURL用法及代码示例
- Node.js URL.fileURLToPath用法及代码示例
- Node.js URL.protocol用法及代码示例
- Node.js URL.resolve(from,to)用法及代码示例
- Node.js URL.format(urlObject)用法及代码示例
- Node.js URL.format用法及代码示例
- Node.js URL.hash用法及代码示例
- Node.js URL.host用法及代码示例
- Node.js URL.hostname用法及代码示例
- Node.js URL.href用法及代码示例
- Node.js URL.origin用法及代码示例
- Node.js URL.password用法及代码示例
- Node.js URL.pathname用法及代码示例
- Node.js URL.port用法及代码示例
- Node.js URL.search用法及代码示例
- Node.js URL.searchParams用法及代码示例
- Node.js URL.createObjectURL(blob)用法及代码示例
- Node.js URLSearchParams.sort()用法及代码示例
- Node.js URLSearchParams.set()用法及代码示例
- Node.js URLSearchParams.toString()用法及代码示例
- Node.js URLSearchParams.keys()用法及代码示例
- Node.js URLSearchParams.getAll()用法及代码示例
- Node.js URLSearchParams.forEach()用法及代码示例
注:本文由纯净天空筛选整理自AshishkrGoyal大神的英文原创作品 Node.js URL.username API。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。