Skip to content

Instantly share code, notes, and snippets.

@juanlopezdev
Created October 23, 2018 17:59
Show Gist options
  • Save juanlopezdev/277b65cdb109cb6a4a3bad844488afec to your computer and use it in GitHub Desktop.
Save juanlopezdev/277b65cdb109cb6a4a3bad844488afec to your computer and use it in GitHub Desktop.
[Obtener extension de un archivo en javascript] Funciones que retornan la extensión de un archivo a traves de su nombre #javascript #utilidades
function getFileExtension1(filename) {
return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : undefined;
}
function getFileExtension2(filename) {
return filename.split('.').pop();
}
function getFileExtension3(filename) {
return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment