Answers for "javascript truncate string full word"

2

javascript truncate string full word

const truncate = (str, max, suffix) => str.length < max ? str : `${str.substr(0, str.substr(0, max - suffix.length).lastIndexOf(' '))}${suffix}`;

// Example
truncate('This is a long message', 20, '...');
Posted by: Guest on July-03-2020

Code answers related to "javascript truncate string full word"

Code answers related to "Javascript"

Browse Popular Code Answers by Language