showing results for - "cut text if too long javascript"
Milly
24 Feb 2016
1if(snippet.length > 1024) {
2text = snippet.substring(0, 1024)//cuts to 1024
3last = text.lastIndexOf(" ")//gets last space (to avoid cutting the middle of a word)
4text = text.substring(0, last)//cuts from last space (to avoid cutting the middle of a word)
5text = text + ` (...)`//adds (...) at the end to show that it's cut
6}