JSFiddle - React, Tailwind, and code Playground

by denniswaltermartinez

JavaScript

var link = 'http://storage.dow.com.edgesuite.net/safety-dow-com/External-Lab-Hazard-Trigger-Grid.pdfaxaxaxax?query=1',
    fileType1 = getFileExtention(link),
    fileType2 = r(link);

function getFileExtention(string) {
    var regex = /(?:\.([^.]+))?$/;
    return regex.exec(string)[1].substring(0, 3);
}

function r(string) {
    var startIndex = string.lastIndexOf('.') + 1,
        endIndex = string.indexOf('?');
    return string.substring(startIndex, endIndex);
}

// output of the file extention
console.log(fileType1, fileType2);