Javascript – Capitalize Each Word in a String

This is a great little function that I whipped up and use to capitalize every word in a string. I can’t tell you how many times I’ve had to use this. Hope you find it useful as I have!


3 thoughts on “Javascript – Capitalize Each Word in a String”

  1. Thanks for this helpful tidbit! I had a similar need and your function provided the answer. In my case, I had to get the first letter of each word in a string (for initials of a person), so this is what mine looks like:

    initials = firstnames.match(/\b[a-z]/g).join(“”).toUpperCase();

  2. Hi!

    I found the same method for capitalizing every word, but was looking for keeping the other letters lowercase. When I saw your code, I facepalmed, for how easy it is, and why I haven’t thought of it before. So, thanks for it! : ) Great site anyway!

    Greetings from Hungary.

    Tamás Márton

Leave a Reply

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