I am using an <input type="file"> element for file upload, and getting the filename. I am now trying to display the file name, but reduce the total string length. To achieve that, I wanted to add an ellipsis at a specific index and display the rest of the characters.
Like for example: if the filename is abcxyz.exe, I want the filename to look like abc..z.exe.
Is there any way to display it in this way ?
I am using this method, but it adds an ellipsis to replace all characters from the position given as a parameter.
function truncate(str, n){
return (str.length > n) ? str.substr(0, n-5) + '…' + str.substring(str.indexOf(".") + 1) : str;
};