This is my solution:
function truncateString(str, num) {
return num >= str.length ? str : str.slice(0, num) + "...";
}
This is my solution:
function truncateString(str, num) {
return num >= str.length ? str : str.slice(0, num) + "...";
}
Did you have a question?
I have added spoiler tags around your code.
If you are sharing your solution just to share it, then we don’t allow that on the forum.
If you had questions then please amend your post
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.