See code:
var file1 = "50.xsl";
var file2 = "30.doc";
getFileExtension(file1); //returns xsl
getFileExtension(file2); //returns doc
function getFileExtension(filename) {
/*TODO*/
}
See code:
var file1 = "50.xsl";
var file2 = "30.doc";
getFileExtension(file1); //returns xsl
getFileExtension(file2); //returns doc
function getFileExtension(filename) {
/*TODO*/
}
If you are looking for a specific extension and know its length, you can use substr:
JavaScript reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
Tested with
Also
A one line solution that will also account for query params and any characters in url.
If you are dealing with web urls, you can use:
Demo: https://jsfiddle.net/squadjot/q5ard4fj/
I just realized that it's not enough to put a comment on p4bl0's answer, though Tom's answer clearly solves the problem: