How can I cut a string after a specific number of characters in JavaScript?
I then want to append the '…' Unicode character. How can I do this?
To split a string at a specific character, you can use the split() method on the string and then pass that character as an argument to the split() method in JavaScript.
Use the . substring() method to get the access the string after last slash.
Method 1: Using slice() Method: The slice() method extracts the part of a string and returns the extracted part in a new string. If we want to remove the first character of a string then it can be done by specifying the start index from which the string needs to be extracted. We can also slice the last element.
Simply
var trunc = "abcdef".substr(0, 3) + "\u2026";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With