trunc javascript code example
Example 1: truncate javascript
function truncateString(str, num) {
if (num > str.length){
return str;
} else{
str = str.substring(0,num);
return str+"...";
}
}
res = truncateString("A-tisket a-tasket A green and yellow basket", 11);
alert(res)
Example 2: javascript trunc
Math.trunc(13.37); // 13
Math.trunc(42.84); // 42
Math.trunc(0.123); // 0