Q:

Write a JavaScript program to truncate a string up to a specified length

0

Write a JavaScript program to truncate a string up to a specified length.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const truncateString = (str, num) =>
  str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;

console.log(truncateString('boomerang', 7));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now