前端学习案例-稀疏数组的遍历问题的研究

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>funciton</title>
</head>
<body>
    <script>
        const arr=[1,,,,2,3,,4,,,,5,6,,,7,,,8,9]

        arr.foreach(item=>{
            console.log(item)//直接打印1,2,3,4,5,6,7,8,9
        })

        arr.find(item=>{
            console.log(item) //,都是undefined
        })
    </script>
</body>
</html>

打印出值

 Array.from.length //1

posted @ 2022-08-13 21:29  前端导师歌谣  阅读(22)  评论(0)    收藏  举报