I am trying to get first key from URL, like this:
const currentUrl = window.location.href;
const parmsFromUrl = new URLSearchParams(currentUrl);
const paramToCheck = parmsFromUrl.keys[0];
But constantly I get undefined, can someone tell how me how to get only first parameter, not a value, I just want key? Thanks.
With
URLSearchParamsyou have to usewindow.location.searchWith
URLyou have to usewindow.location.href
const currentUrl = window.location.search;
const parmsFromUrl = new URLSearchParams(currentUrl);
URLSearchParams.keys() returns an iterator, so you have to use next() to get first value
const paramToCheck = parmsFromUrl.keys().next().value;