eslint for...in 報錯處理


示例代碼:

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>eslint for...in 報錯處理</title>
    </head>

    <body>

        <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
        <script type="text/javascript"> Array.prototype.contains = function(item) { return this.indexOf(item) >= 0 } const arr = [1, 2, 3, 4] for(let key in arr) { //使用hasOwnProperty 處理一下
                if(arr.hasOwnProperty(key)) { console.log(key) } } for(let [key, value] of Object.entries(arr)) { console.log(key + ' ' + value) } </script>
    </body>

</html>

解決方法:

(1)hasOwnProperty 

(2)for of


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM