A simple solution is .split() and .pop() to get the last string in the array, like this:
var ext = fileName.split('.').pop();
This will get you just "txt"
without the .
, just append if needed. This also works on say: My.File.name.has.an extension.txt
as well. If it doesn't have an extension it'll return the file name, so you may want to check for this...or go a completely different direction and validate against a set or known extensions via regex.