首页 > 其他 > 详细

eslint for...in 报错处理

时间:2018-08-22 16:27:49      阅读:1306      评论:0      收藏:0      [点我收藏+]

示例代码:

<!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

eslint for...in 报错处理

原文:https://www.cnblogs.com/mengfangui/p/9517690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!