Have an account? Sign in
Login  Register  Facebook
How can i get file extensions with javascript?
i have a file titled \'file.png\' i want js function to return me \'png\'
Started: September 16, 2011 Latest Activity: September 16, 2011 javascript file
2 Answers
Keep it simple :)
function getFileExtension(filename) {
	return filename.split('.').pop();
}

Posted: misterx704
In: September 16, 2011

Should do it.
function getFileExtension(filename) {
	return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename) : undefined;
}

Posted: xtremex
In: September 16, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer