1const string = "Name".slice(0, 250).concat('...');
2const string2 = "Name".substring(0, 250).concat('...');
1if (string.length > 25) {
2 string = string.substring(0, 24) + "...";
3}
4
5//or
6
7function truncate(str, n){
8 return (str.length > n) ? str.substr(0, n-1) + '…' : str;
9};
10
11//or with CSS
12
13p {
14 white-space: nowrap;
15 overflow: hidden;
16 text-overflow: ellipsis;
17}
18
19//or with replace
20
21short = long.replace(/(.{7})..+/, "$1…");