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

176
Views
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 answers
Answer question

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 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!