Two Quick and Easy Javascript String Methods

Most programming languages have well defined and widely implemented string methods to assist with your string manipulation. Here are two basic but wonderfully useful methods for working with strings in Javascript.

capitaliseFirst

This method easily capitalises the first letter of a string, nice and easy to use, and to understand.

trimToWord

This will trim a string to the nearest word boundary. If you plug in the string “Have a nice day” with a length of 10 you will get back “Have a”. Useful where you need to trim to the nearest word!

And thats it

Just a quick post this one, I hope its been useful to someone. Feel free to comment if you have any changes that you think should be made.

This post has been viewed 1245 times.

Leave a Reply

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