we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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}