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>
相关文章
|
5月前
|
索引 Python
如何优雅地遍历可迭代对象?
如何优雅地遍历可迭代对象?
37 0
|
JavaScript
js:数组、对象序列的遍历迭代
js:数组、对象序列的遍历迭代
154 0
循环遍历的基本用法
循环遍历的基本用法
100 0
循环中逐一添加集合的方法
var tempbd=new List(); foreach (var eitem in bitem) { tempbd.Add(new TempBillDetailsView { StockId = getorder.
496 0
|
3月前
用 for 循环迭代出输出元素
【10月更文挑战第28天】用 for 循环迭代出输出元素。
34 0
|
3月前
for 循环迭代出输出元素
【10月更文挑战第28天】for 循环迭代出输出元素。
30 0
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )
1439 0
【Groovy】集合遍历 ( 使用 for 循环遍历集合 | 使用集合的 each 方法遍历集合 | 集合的 each 方法返回值分析 )
|
6月前
集合中常见方法及遍历方式
集合中常见方法及遍历方式
41 1
|
9月前
各种遍历方法以及注意点
各种遍历方法以及注意点
59 0
ES6—16:迭代数组(forEach)
ES6—16:迭代数组(forEach)
90 0
ES6—16:迭代数组(forEach)

热门文章

最新文章