Extend the String prototype to allow easier title casing.
This commit is contained in:
parent
fb58e20f7a
commit
72bbaadfba
1 changed files with 10 additions and 0 deletions
10
js/prototypes.js
vendored
Normal file
10
js/prototypes.js
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
String.prototype.toTitleCase = function () {
|
||||
let words = this.split(` `);
|
||||
let new_words = [];
|
||||
for (var word of words) {
|
||||
new_words.push(
|
||||
`${word[0].toUpperCase()}${word.slice(1).toLowerCase()}`
|
||||
);
|
||||
};
|
||||
return new_words.join(` `);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue