How do I get the last segment of a url? I have the following script which displays the full url of the anchor tag clicked:
$(\".tag_name_goes_here\").live(\
// https://x.com/boo/?q=foo&s=bar = boo // https://x.com/boo?q=foo&s=bar = boo // https://x.com/boo/ = boo // https://x.com/boo = boo const segment = new URL(window.location.href).pathname.split('/').filter(Boolean).pop(); console.log(segment);
Works for me.