How to get the file extension from a filename using Javascript

var filename = 'myFile.jpg';
var ext = filename.split('.').pop();  //We split the filename on every instance where the . is found and then getting the last element in the array using the pop() function 
alert(ext);

Image Credits: Photo by Isis França on Unsplash.

More Similar Posts

No results found.

Menu