Javascript to extract last parameter of a string after slash(/)

Extract the last parameter of a string which is seperated by a slash using the following line of codes

var str = 'http://example.com/new/samplefiles/file.png';
var n = str.lastIndexOf('/');
var lastParameter = str.substring(n + 1);

here ‘lastParameter‘ will have the value ‘file.png’

Sharing is caring!

Leave a Comment

DON’T MISS OUR GIVEAWAYS!
Subscribe To Newsletter
Subscribe to our newsletter and get all the latest updates offers and giveaways right in your inbox.
Subscribe
Give it a try, you can unsubscribe anytime.
close-link

Join Free Giveaway!

Subscribe to our newsletter to get latest offers and giveaways!
SUBSCRIBE
close-link