JavaScript split() and pop() Program to Get File Extension of Image,Video & PDF Document in Browser Full Project For Beginners

 

 

script.js

 

 

// program to get the file extension

function getFileExtension(filename){

    // get file extension
    const extension = filename.split('.').pop();
    return extension;
}

// passing the filename
const result1 = getFileExtension('module.js');
console.log(result1);

const result2 = getFileExtension('module.txt');
console.log(result2);

Leave a Reply