Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
JavaScript: How to get first parameter, actually first key from URL?

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

With URLSearchParams you have to use window.location.search

With URL you have to use window.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;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!