See code:
var file1 = \"50.xsl\"; var file2 = \"30.doc\"; getFileExtension(file1); //returns xsl getFileExtension(file2); //returns doc function getFileExt
There's also a simple approach using ES6 destructuring:
const path = 'hello.world.txt' const [extension, ...nameParts] = path.split('.').reverse(); console.log('extension:', extension);