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’

Categorized in:

Javascript,