Determine File Extensions Using JavaScript
Written by Cory S.N. LaViska on March 19th, 2008
A handy JavaScript function to get file extensions.
fileExt()
function fileExt(path) {
return path.substr(path.lastIndexOf('.') + 1);
}
return path.substr(path.lastIndexOf('.') + 1);
}
Sample Output
| Input | Output() |
|---|---|
| file.ext | ext |
| /folder/subfolder/file.ext | ext |
| file.bak.ext | ext |

Comments
You can be the first person to comment on this article!