Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Truncate a string

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}
Source by forum.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #Truncate #string
ADD COMMENT
Topic
Name
5+5 =