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

178
Vistas
Unquote key value from Object.fromEntries() result. (javascript)

I'm trying to get a js object from an URL key:value pairs. For that I'm using "Object.fromEntries()" but when I got the result, it returns an object with all the keys quoted, so when I try to access its value I got an error.

Does somebody knows how to solve that, pls?

This is the code:

const params = window.location.search;
const obj = Object.fromEntries(new URLSearchParams(params))
console.log(obj);  

...and this is what it returns back:

Object { "user-name": "phill", "user-lastname": "smith" }

​How can I remove quotes from: user-name and user-lastname keys.?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't remove the quotes, because keys with special characters require quotes. However, you can access them using brackets notation obj['user-name'].

The other option is to get the param from the URLSearchParams instance using URLSearchParams.get():

const params = 'user-name=phill&user-lastname=smith';

const searchParams = new URLSearchParams(params);

const obj = Object.fromEntries(searchParams)

console.log(searchParams.get('user-name'));
console.log(obj['user-name']);

about 4 years ago · Juan Pablo Isaza 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