Home > shorts > Truncate a string with JavaScript

Truncate a string with JavaScript


Truncate a string with JavaScript

const truncate = (str, n) => (
  str.length > n && str.slice(0, n) + '...'
)

Check the demo here => CodePen

© 2021, Andrew Losseff