Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Truncate a string

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

truncateString("Lorem Ipsum placeholder text in any number of characters, words sentences or paragraphs", 9)  // returns Lorem Ips...
Source by github.com #
 
PREVIOUS NEXT
Tagged: #Truncate #string
ADD COMMENT
Topic
Name
5+6 =