Skip to main content

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'

Comments