1var fileName = "myDocument.pdf";
2var fileExtension = fileName.split('.').pop(); //"pdf"
1// Use the lastIndexOf method to find the last period in the string, and get the part of the string after that:
2
3var ext = fileName.substr(fileName.lastIndexOf('.') + 1);
4
1function getFileNameWithExt(event) {
2
3 if (!event || !event.target || !event.target.files || event.target.files.length === 0) {
4 return;
5 }
6
7 const name = event.target.files[0].name;
8 const lastDot = name.lastIndexOf('.');
9
10 const fileName = name.substring(0, lastDot);
11 const ext = name.substring(lastDot + 1);
12
13 outputfile.value = fileName;
14 extension.value = ext;
15
16}
1var fileName = "myDocument.pdf";
2var fileExtension = fileName.split('.').pop(); //"pdf"