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

127
Views
Get portion of URL path and store value in string

So I have code below, and I'm trying to get the store name part of the URL without the gibberish values in between.

    let storeName = request.url.split('/');
    console.log("storeName before: ", storeName);
    storeName = storeName.toString().replace("%20", " ");
    storeName = storeName.toString().replace("%20", " ");
    storeName = storeName.toString().replace(",data,", " ");
    console.log("storeName after: ", storeName);

I attempt to get rid of the %20 symbols and ",data," part that show up in the URL, but I'm having trouble narrowing down that entire URL to just the string "Sarah's Day Salon" and assign that value to the storeName variable. Right now, I was able to narrow the string down to below, but there's a huge spacing issue at the start of the string, and I'm also not sure if this is the most efficient way to capture the "Sarah's Day Salon" part from the URL. I was wondering if anyone has any suggestions as to how I could narrow the URL down to just the store name only?

Printing values from code above:

    storeName before:  [ '', 'data', "Sarah's%20Day%20Salon" ]
    storeName after:   Sarah's Day Salon
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use the decodeURI function for that, no need to replace the %20s with " ", just parse in the url as is and it will remove all special characters.

const url = "/data/Sarah's%20Day%20Salon";
const decodedString = decodeURI(url);
const stringArray = decodedString.split('/');
const storeName = stringArray[stringArray.length - 1]
console.log(storeName);

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!