Menu

gitpiper

truncateString javascript Code Snippet in 2022

stringbeginner

Last Updated: 25 September 2022

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 September 2022

Subscribe to our Newsletter

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

© 2022 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! ✌️