我有存储字符串变量在它的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