Truncate a String by Custom Length in jQuery

Posted on September 29, 2019 at 4:48 pm

Simple function to truncate a string in jQuery:

function truncateString(input, max){ if (input.length > max) return input.substring(0, max) + '...'; else return input; };

Here is an example usage:

$('#filename').html("File: " + truncateString(file.name, 50));

Receive updates via email

Other Posts

Updated Posts