Skip to content

Instantly share code, notes, and snippets.

@kolber
Created December 2, 2009 00:18
Show Gist options
  • Save kolber/246771 to your computer and use it in GitHub Desktop.
Save kolber/246771 to your computer and use it in GitHub Desktop.
//
// Simple javascript truncate function
//
// Extend the string object to allow truncation
String.prototype.truncate = function(length) {
return this.length > length ? this.substring(0, length) + '…' : String(this);
}
// Usage
var str = "My very very very very very long string".truncate(25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment