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

229
Views
Parse url with ./, ../, ../../ etc

Say I have a URL like such:

https://example.com/cheesey_poofs/../goo

How would I make it parse to something like so?

https://example.com/goo
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const url = new URL('https://example.com/cheesey_poofs/../goo');

console.log(url);

about 4 years ago · Juan Pablo Isaza Report

0

A bit long operation using string split

let input = 'https://example.com/cheesey_poofs/../goo';
let input_arr = input.split('//');
let protocol = input_arr[0] + '//';
let url = input_arr[1];
let url_arr = url.split('/');
let result =  protocol + [url_arr[0], url_arr[url_arr.length-1]].join('/');

console.log(result);

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!