Created
December 2, 2009 00:18
-
-
Save kolber/246771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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