Get the Query string parameters and values in JavaScript/TypeScript
Sometimes you need to get the parameters and values from the query string in your JavaScript/TypeScript applications. If you don't want to spend the time on making your own methods, you can use this one with URLSearchParams.
For example. the URL looks this way:
https://markimarta.com/sites/Euro2024/_layouts/15/workbench.aspx?pollId=13
To extract the 'pollId' value you can use the code below:
const urlParams = new URLSearchParams(window.location.search);
const pollId:number = parseInt(urlParams.get('pollId'))
As you can see, it's easy.