1

How to use javascript to get the following url - the value of id?

URL: http://www.url/id/2721/John

I would get the following values:

2721 and John
4

2 Answers 2

3

Use .split("/") to separate the URL into pieces, then read the values.

Sign up to request clarification or add additional context in comments.

Comments

0

Use .match(re):

var r = "http://www.url/id/2721/John".match('\/id\/(\\d+)/([^/]+)');

The value v[1] will be 2721 and r[2] will be John.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.