Reputation: 14142
I have the following string :-
http://myapp.local/myapp/shop/products/admin/ShopProducts%5Bproduct_name%5D//ShopProducts%5BemailNotification%5D//ShopProducts%5Bemail_user%5D//ShopProducts%5Bactive%5D//ShopProducts%5Binstant_win%5D//ShopProducts%5Bmulti_buy%5D//ShopProducts%5Bprice%5D//ShopProducts%5Bquantity%5D//ShopProducts_page/2/ajax/shopproducts-grid
I only want to grab the last section as so on.. not this is a part of pager (needs some weird custom hack) and the page number in this case is 2 but could 2,3,4, 500...
ShopProducts_page/2/ajax/shopproducts-grid
What is the easiest way to do this using vanilla js or jquery or a structured way to grab the parts into some of an array that I'll be able to manipulate?
Upvotes: 0
Views: 75
Reputation: 1326
If there will always be double forward-slashes //
in the path, you can simply do this:
//Where string is already defined to be the path
var sections = string.split('//');
var lastSection = sections[sections.length-1];
Upvotes: 2