首页 > 编程语言 > 详细

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

时间:2018-06-24 16:34:59      阅读:268      评论:0      收藏:0      [点我收藏+]

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>

技术分享图片

 

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

原文:https://www.cnblogs.com/-Tony/p/9220812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!