potong teks jika terlalu lama javascript

if(snippet.length > 1024) {
text = snippet.substring(0, 1024)//cuts to 1024
last = text.lastIndexOf(" ")//gets last space (to avoid cutting the middle of a word)
text = text.substring(0, last)//cuts from last space (to avoid cutting the middle of a word)
text = text + ` (...)`//adds (...) at the end to show that it's cut
}
Pbknowall