Skip to content

Instantly share code, notes, and snippets.

@jhonsore
Last active October 2, 2021 17:08
Show Gist options
  • Save jhonsore/b636f7461e69399907bfd06ce64feb94 to your computer and use it in GitHub Desktop.
Save jhonsore/b636f7461e69399907bfd06ce64feb94 to your computer and use it in GitHub Desktop.
Get file extension
// methood 1
function getFileExtension(filename:string) {
return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}
// method 2
function getFileExtension(filename:string) {
filename.substring(filename.lastIndexOf('.')+1);
}
function getFileName(name:string){
return name.replace(/\.[^/.]+$/, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment