JSFiddle - React, Tailwind, and code Playground
by pramendra
JavaScript
function truncate (text, limit, append)
{
trunc = text;
if (typeof text !== 'string')
return '';
if (typeof append == 'undefined')
append = '...';
if (trunc.length > limit)
{
trunc = trunc.substring(0, limit);
trunc = trunc.replace(/w+$/, '');
}
//trunc.push(append);
return trunc;
}
response = truncate("THIS IS NEW HOME, DOGS ARE PLAYING ALL THE WAY TO.",10);
alert(response);