How can I get file extensions with JavaScript?

后端 未结 30 2409
终归单人心
终归单人心 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:12

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

    edit: Strangely (or maybe it's not) the $1 in the second argument of the replace method doesn't seem to work... Sorry.

提交回复
热议问题