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

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

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>
相关文章
|
1月前
thymeleaf如何迭代遍历,如何判断
thymeleaf如何迭代遍历,如何判断
|
9天前
|
C语言
循环迭代判断\丢番图
循环迭代判断\丢番图
13 2
|
1月前
|
C#
C# 循环遍历使用
C# 循环遍历使用
138 0
|
10月前
jsx种map循环中使用if判断
jsx种map循环中使用if判断
59 0
|
8月前
|
存储 JavaScript 前端开发
JS的for循环,forin循环,forof循环,foreach循环map循环以及,reduce()循环 方法最实用详解。
JS的for循环,forin循环,forof循环,foreach循环map循环以及,reduce()循环 方法最实用详解。
|
8月前
循环遍历的基本用法
循环遍历的基本用法
55 0
|
存储 算法 前端开发
嵌套遍历同一个数组的时候,试试Map优化
嵌套遍历同一个数组的时候,试试Map优化
123 0
|
JavaScript
js:数组、对象序列的遍历迭代
js:数组、对象序列的遍历迭代
108 0
|
存储 程序员
map的常见用法与五种常见循环遍历源码
小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )
1309 0
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )