Last active
December 28, 2019 21:16
-
-
Save pedroCX486/21e6996d7aee715e369d6148c83b38b5 to your computer and use it in GitHub Desktop.
Truncate in JS/TS
This file contains 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
truncate(text, length) { | |
if (text.length <= length) { | |
return text; | |
} else { | |
return text.substring(0, length) + '...'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment