slice - url string, jquery/js get numbers that are between two slashes -
i'm working on forum has url's so:
http://www.place.com/forum/d7/2/ http://www.place.com/forum/d7/22/ http://www.place.com/forum/d7/234/ http://www.place.com/forum/d7/9999/ http://www.place.com/forum/d7/98765/
/d7/ username /2/ user id
the user id's go 1 to, let's unlimited.
how 'get' user id?
i figured out how if it's 1 number, e.g., 2. how tell @ every number between last 2 slashes?
this answer seek.
var url = "http://www.place.com/forum/d7/9999/".split("/"); var id = url[url.length - 2];
this work if there trailing /
.
if there not, -1
instead of -2
, if check last character, can use understanding.
var url = "http://www.place.com/forum/d7/9999/"; var islastslash = (url[url.length -1]=="/")? true: false; var url= url.split("/"); var id = url[url.length - (islastslash? 2: 1)]; return id;
Comments
Post a Comment