Here's a post with different approaches: https://www.codeqazone.com/title-case-strings-javascript/ maybe it could be helpful for someone. And it also includes the first solution proposed here.