es6:for...of循环遍历迭代对象

拜拜、爱过 提交于 2019-12-18 09:14:54

es6:for…of循环遍历迭代对象

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<body>
    <script>
        const names = ['zhang','li','deng','mongodb'];


        // for(let name of names.entries()){//.entries()得到数组中的索引值和值  不适用与对象
        //     console.log(name);
        // }


        // function sum() {
        //    let total = 0;
        //    for(let num of arguments){
        //        total = total + num;
        //    }
        //    console.log(total)
        //    return total;
        // }

        // sum(10,20,10,10,120);

        let name = 'ugfuishdihs';
        for(let  nam of name){
            console.log(nam)
        }


        // for...of.. 也可以用于 NODElist
    </script>
</body>
</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!