Xpode.com        Click here to Print this article.

how to extract extension from filename string in javascript

We can find any file extension with function. It will split the characters from last dot and show all characters after that. Please see below working example.

var fileExt = filename.split('.').pop();
If there will be no “.” Dot in value then it will show entire string.


'some_value' = 'some_value'

'.html = 'html'

'../images/myimage.cool.jpg' = 'jpg'


Contributed by:
Rohit kakria
I am software developer

Resourse address on xpode.com

Click here to go on website