0

I have the following string.

http://localhost:8080/test/tf/junk?tx=abc&xy=12345

Now I want to get substring between the third and fourth slash "/" using javascript.

To be more clear, I want to extract test from the above given string. Can anybody help me out on this?

1
  • var index = location.pathname.indexOf("/"); location.pathname.substring(0, index) Commented Jun 15, 2017 at 10:27

1 Answer 1

2

You can split your string into an array

var str = "http://localhost:8080/test/tf/junk?tx=abc&xy=12345";
str = str.replace("http://", "");
var array = str.split("/");
for(var i = 0; i < array.length; i++) {
  alert(array[i]);
}

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

1 Comment

Thanks for the response. Plus One for quick response.

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.