var filename = 'myFile.jpg';
var ext = filename.split('.').pop();  //We split the filename on every instance where the . is found and then getting the last element in the array using the pop() function 
alert(ext);