Truncates str to maxLength characters, appending suffix when truncation occurs. The total length of the returned string never exceeds maxLength.
str
maxLength
suffix
The input string.
Maximum allowed length of the result.
String appended when truncating. Defaults to "...".
"..."
truncate("Hello, World!", 8) // => "Hello..."truncate("Hello, World!", 8, "…") // => "Hello,…"truncate("Hi", 10) // => "Hi" Copy
truncate("Hello, World!", 8) // => "Hello..."truncate("Hello, World!", 8, "…") // => "Hello,…"truncate("Hi", 10) // => "Hi"
Truncates
strtomaxLengthcharacters, appendingsuffixwhen truncation occurs. The total length of the returned string never exceedsmaxLength.