I have a long text. ex:
var text = "get snippet text using javascript?";
How can I write a method to get the snippet, not substring:
Ex: snippet(text,10) -> “get snippet…” not “get snippe” (10 characters). it means if the last character not a space or dot, we must get more characters until reach space or dot.
Any help?
Not tested thoroughly:
You can add the ellipsis when the returned string is shorter than original string.