I need to display a text as paragraph, but display only three lines and truncate the test while adding ...(three dots) in the paragraph end.
Create a function truncate(str, maxlength) that checks the length of the str and, if it exceeds maxlength – replaces the end of str with the ellipsis character "…" , to make its length equal to maxlength . The result of the function should be the truncated (if needed) string.
Calculate max length of string which can fit into 3 lines and use the following script
var maxLength = 140;
var result = yourString.substring(0, maxLength) + '...';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With