Truncate string to nearest white space using Javascript No ratings yet.

By | May 20, 2016

Method One:

Set the length. So that after the 10th character, if any space appears the string will get truncated.

Output:

 

Method two:

Output:

 

Method three: Using regular expresion

Output:

 

Likes(0)Dislikes(0)

Please rate this

One thought on “Truncate string to nearest white space using Javascript

Leave a Reply

Your email address will not be published. Required fields are marked *