Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda