return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename) : undefined;
or
return filename.split('.').pop();
please refer to this link for more details - LINK
If you only need a txt file
save it in a variable and use the if else statement to check it
var file=file.split('.').pop(); if (type=='txt'){ //do something }else{ //do something }
source share