String.prototype.length
is greater than num
.'...'
appended to the end or the original string.const truncateString = (str, num) => str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
truncateString('boomerang', 7); // 'boom...'
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️