A memo on how to output file extension in JavaScript. For example, extract file extensions (pdf, txt, html) from URLs obtained with document.location.href.
function getFileExtension(filename) {
return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : undefined;
}
getFileExtension(document.location.href);