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

238
Views
Extracting certain values from a large URL string in javascript?

I have a big URL hash that is given in string form and need to extract each part of it:

type=recovery&access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhdWQiOiJhdXRoZW50aWNhdGV&expires_in=3600&refresh_token=sYlurmTtfrAhyHl39Oqwww&token_type=bearer&type=recovery

I have tried substr() but it isn't reliable because each item may have a differing amount of characters each time.

What's the best way to extract type, access_token, expires_in, refresh_token, token_type reliably?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

You could use URL:

// Adding a dummy domain so the string is a valid url
let x = new URL('http://dummydomain.tpl/dummyfile.ext?' + 
'type=recovery&access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhdWQiOiJhdXRoZW50aWNhdGV&expires_in=3600&refresh_token=sYlurmTtfrAhyHl39Oqwww&token_type=bearer&type=recovery');

x.searchParams.get("refresh_token")
about 4 years ago · Santiago Gelvez Report

0

Please use URLSearchParams

var urlSearchParams = new URLSearchParams("type=recovery&access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhdWQiOiJhdXRoZW50aWNhdGV&expires_in=3600&refresh_token=sYlurmTtfrAhyHl39Oqwww&token_type=bearer&type=recovery")

const params = Object.fromEntries(urlSearchParams.entries());

console.log(params)

about 4 years ago · Santiago Gelvez 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!