How can I get file extensions with JavaScript?

后端 未结 30 1843
终归单人心
终归单人心 2020-11-22 09:37

See code:

var file1 = \"50.xsl\";
var file2 = \"30.doc\";
getFileExtension(file1); //returns xsl
getFileExtension(file2); //returns doc

function getFileExt         


        
30条回答
  •  情话喂你
    2020-11-22 10:25

    I just realized that it's not enough to put a comment on p4bl0's answer, though Tom's answer clearly solves the problem:

    return filename.replace(/^.*?\.([a-zA-Z0-9]+)$/, "$1");
    

提交回复
热议问题