A little late ... I had to answer. This is the easiest way.
Step by step. .padEnd - Guaranteed string length
"The padEnd () method completes the current line with the given line (repeated if necessary) so that the resulting line reaches the specified length. The filling is applied from the end (right) of the current line. The source for this interactive Example is stored in the GitHub repository." Source: developer.mozilla .org / en-US / docs / Web / JavaScript / Reference / ...
.substring - restriction on the required length
If you decide to add ellipses, add them to the output.
I gave 4 examples of common use of JavaScript. I highly recommend using the String prototype with Overloading to support previous versions. This greatly facilitates implementation and change later.
Matthew Egan Jan 24 '19 at 0:35 2019-01-24 00:35
source share