GitHub 6248★

Get the file name from a URL

JavaScript version

const fileName = (url: string): string => url.substring(url.lastIndexOf('/') + 1);

TypeScript version

const fileName = (url: string): string => url.substring(url.lastIndexOf('/') + 1);

Examples

fileName('http://domain.com/path/to/document.pdf'); // 'document.pdf'
Follow me on and to get more useful contents.