Truncate a string with JavaScript
const truncate = (str, n) => ( str.length > n && str.slice(0, n) + '...' )
Check the demo here => CodePen