Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:04:32+00:00 2026-06-17T10:04:32+00:00

I need to have a URL Parser written in JavaScript, that will work as

  • 0

I need to have a URL Parser written in JavaScript, that will work as described below:

Assuming you have this URL http://www.somedomain.com/a/b/c

Then the function parseURL(n) will work as follows:

var paramA = parseURL(1) // Sets paramA to "a"
var paramB = parseURL(2) // Sets paramB to "b"
var paramC = parseURL(3) // Sets paramC to "c"
var paramD = parseURL(4) // Sets paramD to null (because the path does not ripple down to d)

also note that if I pass this URL http://www.somedomain.com/a/b/c/ (note that I added a backslash at the end of the URL) then the function will still work the same way.

This function should work on any URL of any length, so it should work on a longer URL as this one: http://www.somedomain.com/a/b/c/d/e/. For this URL. we can go up to parseURL(5) which should return “e”, but parseURL(6) or parseURL(7) will both return null.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:04:33+00:00Added an answer on June 17, 2026 at 10:04 am
    function parseURL(i) {
       var t = document.location.pathname.split('/');
       return i < t.length ? t[i] : null;
    }
    

    As pointed by VisioN, to deal with ending /, this version would be better :

    function parseURL(i) {
       var t = document.location.pathname.replace(/\/+$/, "").split('/');
       return i < t.length ? t[i] : null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this youtube url http://www.youtube.com/watch?v=9N51Etoikfw&feature=youtube_gdata i need to remove the feature parameter and
I have URL like this: http://localhost/PMApp/temp.htm?ProjectID=462 What I need to do is to get
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I have written a helper function that can retrieve content from a url. This
I have this requirement that I need to replace URL in CSS, so far
Hi have this URL string which I need to extract possibly using regex but
I have a URL that I need to call from a PHP script. The
I have a url that looks like that http://example.com/index.php?id=111&title=word1 word2 word3 I need to
I have a long URL on a web page in Windows that I need
I need to use mod_rewrite to redirect http://www.site.com/new_cars/cars.php?make=brandname to have a friendlier url of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.