Skip to content

Instantly share code, notes, and snippets.

@WebSofter
Created September 24, 2021 12:29
Show Gist options
  • Save WebSofter/40eccfadb4551d306a4e309db6baf7b6 to your computer and use it in GitHub Desktop.
Save WebSofter/40eccfadb4551d306a4e309db6baf7b6 to your computer and use it in GitHub Desktop.
Get file extension in JS
function getFileExtension(filename){
let ext = /^.+\.([^.]+)$/.exec(filename)
return ext == null ? '' : ext[1].length < 5 ? ext[1] : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment