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
  • 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
  • 21,342
  • 4
  • 27
  • 50
Kiran Shahi
  • 6,738
  • 6
  • 35
  • 66
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,219
  • 2
  • 12
  • 24