Get File Extension

by Aymen on 08/24/2017

Ho do you get File Extension in JavaScript ?

Using split() and pop() methods

var fileName = "my-picture.jpeg";var ext = fileName.split('.').pop();console.log(ext) // jpeg

How about Regular Expression ?

var fileName = "my-picture.jpeg";var ext = /[^.]+$/.exec(fileName)[0];console.log(ext) // jpeg

If you have any other methods leave a comment.

🙂

No comments yet.

Write a comment: