Categories
Truncates a string to a specified length.
Contributed by @itsbrunodev
function truncate(str, num) { return str.length > num ? str.slice(0, num) + "..." : str; }
truncate("Hello World", 5); // "Hello..."