function truncateString(str, num) {
// Clear out that junk in your trunk
if(num >= str.length){
return str;
}
if(num > 3){
return str.substring(0,num-3) + "...";
} else {
return str.substring(0,num) + "...";
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
No comments:
Post a Comment