DEV Community

Discussion on: Truncate a String

Collapse
 
michey85 profile image
Mikhail Nepomnyashchiy

What about immutable version?

function truncateString(str, num) {
return str.length > num ?
str.slice(0,num)+"..."
:
str;
}

Collapse
 
xmohammedawad profile image
Mohammed Awad

wow, nice and simple