It becomes a hassle when working with a too-long string, don't worry,
today, in this article I will be showing an easy to come out from that hassle by trimming/truncating the string.
const truncate = (str, num) => {
return str.length > num ? str.slice(0, num) + "..." : str;
}
const str = "the quick brown fox jumps over the lazy dog"
truncate(str, 18)
Thank you for reading, have a nice day!
- Follow me on Twitter - @dhairyashah_dev
- Subscribe me on YouTube - Channel Cover Photo by Fakurian Design on Unsplash
Top comments (0)