Skip to content

Instantly share code, notes, and snippets.

@Hoxtygen
Last active December 1, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hoxtygen/f0da3cb6192674ebcac506012ceaff42 to your computer and use it in GitHub Desktop.
Save Hoxtygen/f0da3cb6192674ebcac506012ceaff42 to your computer and use it in GitHub Desktop.
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num) {
if (num <= 3) {
str= str.slice(0, num) + "...";
} else {
str = str.slice(0, num-3) + "...";
}
}
return str;
}
truncateString("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