Full credits to this thread
const getFileExtension = (filename) => {
const splitedName = filename.split('.');
console.log(splitedName) // [ 'fileblabla', 'pdf' ]
if (splitedName.length === 1 || (splitedName[0] === '' && splitedName.length === 2)) {
return '';
}
return splitedName.pop();
};
const result = getFileExtension('fileblabla.pdf')
console.log(result) // pdf