Skip to content

Instantly share code, notes, and snippets.

@BorisKotlyarov
Created August 13, 2018 20:36
Show Gist options
  • Save BorisKotlyarov/788b34de05298836d4b3276281938ab0 to your computer and use it in GitHub Desktop.
Save BorisKotlyarov/788b34de05298836d4b3276281938ab0 to your computer and use it in GitHub Desktop.
String.prototype.toCapitalize = function () {
let arr = this.toLowerCase().split(" ");
arr.forEach((item, index) => {
arr[index] = item[0].toUpperCase() + item.substr(1);
});
return arr.join(" ");
}
let string = `hello world! this is TEST string`;
console.log(string.toCapitalize());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment