概述
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>
更多专业前端知识,请上 【猿2048】www.mk2048.com
最后
以上就是敏感冬瓜为你收集整理的Jsの练习-数组常用方法 -forEach()的全部内容,希望文章能够帮你解决Jsの练习-数组常用方法 -forEach()所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复