There's no need to parse the URL as a string. You can let the browser do it for you (and even modify the parameters this way):
const params = new URL(document.URL).searchParams;
// checking for params
params.has("u")
// getting a param
params.get("username")