Skip to content

Instantly share code, notes, and snippets.

@nash403
Created December 20, 2016 08:53
Show Gist options
  • Save nash403/7b888414231ea79a483239ad891dfdc1 to your computer and use it in GitHub Desktop.
Save nash403/7b888414231ea79a483239ad891dfdc1 to your computer and use it in GitHub Desktop.
An efficient way to get a file extension from the file's name
// Does not handle hidden files like .htaccess the way you would want though ;)
getFileExtension (filename) {
let res = filename.substr(filename.lastIndexOf('.')+1);
return res === filename ? '' : res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment