📜  如果太长,请剪切文本 javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:17.429000             🧑  作者: Mango

代码示例1
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
}