1const string = "Name".slice(0, 250).concat('...');
2const string2 = "Name".substring(0, 250).concat('...');
1var string = "ABCDEFG";
2var truncString = string.substring(0, 3); //Only keep the first 3 characters
3console.log(truncString); //output: "ABC"
1function truncateString(str, num) {
2 if (num > str.length){
3 return str;
4 } else{
5 str = str.substring(0,num);
6 return str+"...";
7 }
8
9}
10
11res = truncateString("A-tisket a-tasket A green and yellow basket", 11);
12alert(res)