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