Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add ellipsis to any text. Choose amount of words to show.
String.prototype.ellipsis = function(numOfWords, _text, wordCount ) {
_text = this;
wordCount = _text.trim().replace(/\s+/g, " ").split(' ').length;
_text = _text.trim().split(' ');
_text.splice(numOfWords, wordCount, "...");
return _text.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.