Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
Last active December 24, 2015 21:39
Show Gist options
  • Save kalinchernev/6867262 to your computer and use it in GitHub Desktop.
Save kalinchernev/6867262 to your computer and use it in GitHub Desktop.
JavaScript function to return an extension for a filename input as a string
// @params string - a string containing a file name
// @return string - the file extension (with no period) if it has one, otherwise false
function getFileExtension(string) {
if (typeof(string) === 'string' && (string.indexOf(".") !== -1)){
var dot=string.indexOf(".");
return string.substring(dot+1, i.length)
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment