If you’re in a modern browser environment (which most of us are these days), this is the best way:
const urlParams = new URLSearchParams(window.location.search);
const value = urlParams.get('yourKey');
console.log(value);
It’s concise, readable, and natively supported in all major browsers.