I have JavaScript Array that store String variable in it. I have tried below code that help me to convert Javascript variable to uppercase letter,
<html>
<body>
<p id="demo"></p>
<button onclick="toUppar()">Click Here</button>
<script>
Array.prototype.myUcase=function()
{
for (i=0;i<this.length;i++)
{
this[i]=this[i].toUpperCase();
}
}
function toUppar()
{
var numArray = ["one", "two", "three", "four"];
numArray.myUcase();
var x=document.getElementById("demo");
x.innerHTML=numArray;
}
</script>
</body>
</html>
but i want to convert only first character of Javascript Variable to Upper case.
Desired output : One,Two,Three,Four
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.
Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.
string str = "something"; str[0] = toupper(str[0]); That's all you need to do.
If you need the upper case for presentation to your views, you can simply use css for do so!
div.capitalize:first-letter {
text-transform: capitalize;
}
here is the complete fiddle example: http://jsfiddle.net/wV33P/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With