示例代码:

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-06-05
  • 2021-08-04
  • 2021-10-17
  • 2021-06-05
  • 2021-06-02
  • 2022-01-30
  • 2021-11-15
相关资源
相似解决方案