Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save svahora/35dd0d115aa7357d0f37 to your computer and use it in GitHub Desktop.
Save svahora/35dd0d115aa7357d0f37 to your computer and use it in GitHub Desktop.
function truncate(str, num) {
var length = str.length;
if(length > num) {
str = str.substr(0, num-3) + "...";
}
return str;
}
truncate('A-tisket a-tasket A green and yellow basket', 11);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment