运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Arrays</h2> <p>The prototype constructor allows you to add new properties or methods to the Array() object.</p> <p id="demo"></p> <script> // Add a new method Array.prototype.myUcase = function() { for (let i = 0; i < this.length; i++) { this[i] = this[i].toUpperCase(); } }; // Use the method on any array const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.myUcase(); document.getElementById("demo").innerHTML = fruits; </script> </body> </html>