You need window.location.search
get query string.
You need window.location.pathname
to get all data after first slash.
For example for this page:
> console.log(window.location.pathname);
/questions/43932650/how-to-extract-query-parameters-from-wordpress-permalinks-in-javascript/43932720#43932720
> console.log(window.location.search);
'' // becase there is no query string
After that you have to parse query string. You need this:
window.location.search.substr(1).split('&').map(function (value) {
var data = value.split('=');
return {
param : data[0],
value : data[1]
}
});
For this tring
https://www.google.ru/search?q=javascript+location+get+parameters&oq=javascript+location+get+parameters&aqs=chrome..69i57j0l5.6512j0j7&sourceid=chrome&ie=UTF-8
the result will be:

Now, you need something similar to parse pathname. I don't know specific of how this string is built from WP side so I can't help there.