Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to truncate string in javascript

function truncateString(str, num) {
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #truncate #string #javascript
ADD COMMENT
Topic
Name
4+6 =