当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Jsの练习-数组常用方法 -forEach()

Jsの练习-数组常用方法 -forEach()

2018年06月25日  | 移动技术网IT编程  | 我要评论

方艺蒙,白猫图库,万庆良与叶家关系

forEach()  : 对数组进行遍历循环,对数组中的每一项运行给定函数。

格式: arr.forEach(function(value,index){})

 

<!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>
        var arr = [1, 3, 5, 7, 9, 11,'哈哈'];
        arr.forEach(function (value, index) {
            console.log(index + ':' + value);
        })
    </script>

</body>

</html>

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网