URL and URLSearchParams
The global URL class parses addresses and URLSearchParams reads and builds query strings.
Example
const u = new URL('https://example.com:8080/docs/a?x=1&y=two#top');
console.log(u.hostname, u.port, u.pathname, u.hash);
console.log(u.searchParams.get('y'));
u.searchParams.append('z', '3');
console.log(u.href);Result
example.com 8080 /docs/a #top two https://example.com:8080/docs/a?x=1&y=two&z=3#top
Exercise
Read a query value.
u.searchParams.("x")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.