0

I have url like :

    http://localhost/index/2/99

through jquery or javascript i want to get the id 2 how can i get this value

i used like:

var url=document.URL;
alert(url.match(/\d+/));

output is:8000

Shruti
  • 149
  • 1
  • 9

2 Answers2

2

you can get the url path and get the value by index.

var url = window.location.href.split('/');
console.log(url[3]);
prasanth
  • 22,145
  • 4
  • 29
  • 53
Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
0

You can get value by using index. url.match(/\d+/) gives you an array You can get it by index position like following:

var url = "http://localhost/index/2/99";
var value = url.match(/\d+/);
console.log(value[0]);
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24