js arr_function.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>js arr_function</title>
</head>
<body>
<p id="demo"></p>
<button οnclick="f()">点我</button>
<script>
    /*参考:https://www.cnblogs.com/1666818961-lxj/p/7404768.html*/
    Array.prototype.upperCase = function () {
        // this,代表Array.
        for (let i = 0; i < this.length; i++) {
            this[i] = this[i].toUpperCase();
        }
    };

    function f() {
        let fruits = ["Banana", "Orange", "Apple", "Mango"];
        fruits.upperCase();
        let demo = document.getElementById("demo");
        demo.innerHTML = fruits;
        // BANANA,ORANGE,APPLE,MANGO
    }
</script>
</body>
</html>


发布了197 篇原创文章 · 获赞 61 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/105182162