A Beautiful Site

Determine file extensions using JavaScript

A drawing of a cartoon man pointing upwards

Heads up! This post was written in 2008, so it may contain information that is no longer accurate. I keep posts like this around for historical purposes and to prevent link rot, so please keep this in mind as you're reading.

— Cory

A quick JavaScript function to determine a file's extension.

function fileExt(path) {
  return path.substr(path.lastIndexOf('.') + 1);
}