Skip to content

Instantly share code, notes, and snippets.

@cdmz
Created July 31, 2015 13:27
Show Gist options
  • Save cdmz/1741bf9c81285e3f3260 to your computer and use it in GitHub Desktop.
Save cdmz/1741bf9c81285e3f3260 to your computer and use it in GitHub Desktop.
Get extension file by path javascript
var path = "http://localhost/project/temp/folder/file.mp4";
var array = path.split('/'); // split /
var ultimo = array.pop(); // get last index
var basename = ultimo.split('.'); // splt .
var extension = basename.pop(); // get last index
alert(extension);
// OR
var path ="http://localhost/project/temp/folder/file.mp4";
var array = path.split('.'); // splt .
extension = array[array.length -1 ]; // get last index
alert(extension);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment