Answers for "truncate a strin g"

4

How to make string shorter javascript

const string = "Name".slice(0, 250).concat('...');
const string2 = "Name".substring(0, 250).concat('...');
Posted by: Guest on February-22-2020
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)
Posted by: Guest on July-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language