getParameterByName
Stackoverflow answer packaged as NPM package.
Usage
Use in browser
<script src="https://unpkg.com/getparameterbyname/dist/bundle.min.js"></script>
<script>
const url = 'https://www.example.com/search?q=nodejs';
const queryParameterValue = getQueryParameterByName('q', url);
// Print queryParameterValue to console
console.log(queryParameterValue);
</script>
Get query parameter from url
import getQueryParameterByName from 'getqueryparameterbyname';
const url = 'https://www.example.com/search?q=nodejs';
const queryParameterValue = getQueryParameterByName('q', url);
If no second parameter is set, window.location.href is used.