I have a url like this
http://example.com/param1/param2/param3
Please help me get the second last parameter using javascript. I searched and could only find regex method to find the last parameter. I am new to this. Any help would be greatly appreciated.
Thanks.
var url = 'http://example.com/param1/param2/param3';
var result= url.split('/');
var Param = result[result.length-2];
Demo Fiddle:http://jsfiddle.net/HApnB/
Split() - Splits the string into an array of strings based on the separator you mentioned
In the above , result
will be an array that contains
result = [http:,,example.com,param1,param2,param3];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With