Menu

gitpiper

truncateString javascript Code Snippet in 2024

stringbeginner

Last Updated: 13 March 2024

Truncates a string up to a specified length.

  • Determine if String.prototype.length is greater than num.
  • Return the string truncated to the desired length, with '...' appended to the end or the original string.
const truncateString = (str, num) => str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
truncateString('boomerang', 7); // 'boom...'

javascript snippet similar to truncateString For You in March 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️