Get current page name without query string

How do I modify this to return the current page name without query string please?

document.write(location.href.split("/").slice(-1));

thanks …

Hi @pmaher1705, the location has more properties than just href; e.g. you might do

console.log(location.origin + location.pathname)

The location documentation page has the answers for you there.
You can also console.log(location) to see a live example of all the different properties.

location.pathname gives the current page name with no query string.

document.write(location.pathname.split("/").slice(-1));