我有存儲字符串變量在它的JavaScript數組。 我曾嘗試下面的代碼,幫助我的Javascript變量轉換爲大寫字母,轉換字符串的第一個字符內爲大寫
<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>
,但我想JavaScript變量的只有第一個字符轉換爲大寫。
所需的輸出:One,Two,Three,Four
'@ thgaskell'我需要與JavaScript數組不直接對Java腳本變量。 – Vijay
在這種情況下看一看['Array.map'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map):) – thgaskell