Skip to content

Tag: truncation

Smart way to truncate long strings

Does anyone have a more sophisticated solution/library for truncating strings with JavaScript and putting an ellipsis on the end, than the obvious one: Answer Essentially, you check the length of the given string. If it’s longer than a given length n, clip it to length n (substr or slice) and add html entity … (…) to the clipped string. Such