Answers for "uppercase string JS"

98

javascript capitalize string

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Posted by: Guest on July-22-2019
49

uppercase javascript

var str = "Hello World!";
var res = str.toUpperCase();  //HELLO WORLD!
Posted by: Guest on July-30-2020
2

capitalize string js

With performance metrics...

// 10,889,187 operations/sec
function capitalizeFirstLetter(string) {
    return string[0].toUpperCase() + string.slice(1);
}

// 10,875,535 operations/sec
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

// 4,632,536 operations/sec
function capitalizeFirstLetter(string) {
    return string.replace(/^./, string[0].toUpperCase());
}

// 1,977,828 operations/sec
String.prototype.capitalizeFirstLetter = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}
Posted by: Guest on May-28-2021
-1

js to uppercase

var string = "A string";
console.log(string.toUpperCase()); // -> A STRING
Posted by: Guest on July-17-2021
-1

toUpperCase()

let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT    ";
dna = dna.trim().toUpperCase();
console.log(dna);
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language