How to get file extension using javascript/jquery

You can get file extension in HTML using javascript/jquery function. You have to pass the filename to the javascript function and this function returns the format of the file. By using this function you can get that the file is an image (png, jpg, jpeg), pdf, or in any other format.

Answers 1
  • Get file extension using file name with replace method in javascript

        function getFileExtension(fileName){
            var  fileExtension;
            fileExtension = fileName.replace(/^.*\./, '');
            return fileExtension;
        var fileExt = getFileExtension('filename.jpg');
  • Back to code snippet queries related javascript