Monday, May 23, 2011

How get file type using javascript

This is post about how to get the filetype from file name. nothing special just using split() and pop() function

<script>
filename = 'test.php';
alert(filename.split(.).pop());
</script>

alert will return php, because the split function split the filename and return a array as [0]=>'test', [1]=>php.

pop() will pop the last value from array.

No comments:

Post a Comment