how to get file extension in javascript last index

JavaScript
var extension = fileName.substring(fileName.lastIndexOf('.')+1);var fileName = "myDocument.pdf";
var fileExtension = fileName.split('.').pop(); //"pdf"
Source

Also in JavaScript: