Web APIs
URL.pathname
Reads or sets the URL path, excluding query and fragment. For ordinary HTTP(S) URLs it begins with a slash.
Formal Syntax & Structure
javascript syntaxjavascript
url.pathnameReturn Value
string
Path component.
Working Example
Example Snippetjavascript
(async () => {const u=new URL("/items?q=pen#top","https://example.test/api/");console.log(u.pathname,u.search,u.hash);})()