当前位置:网站首页>js遍历数组(用forEach()方法)
js遍历数组(用forEach()方法)
2022-06-23 14:24:00 【刘家奕_】
forEach()方法需要一个函数作为参数
-像这种函数,由我们创建但是不由我们调用的,我们称为回调函数
-数组中有几个元素函数就会执行几次,每次执行时,浏览器会将遍历到的元素
以实参的形式传递进来,我们可以来定义形参,来读取这些内容
-浏览器会在回调函数中传递三个参数:
第一个参数,就是当前正在遍历的元素
第二个参数,就是当前正在遍历的元素的索引
第三个参数,就是正在遍历的数组
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
var arr = ["孙悟空", "猪八戒", "沙和尚", "唐僧", "白骨精"];
arr.forEach(function (value, index, obj) {
console.log(value);
});
</script>
</body>
</html>

边栏推荐
- ts封装请求
- go语言的变量声明
- 【opencv450】椒盐噪声demo
- Millions of bonuses are waiting for you to get. The first China Yuan universe innovation and application competition is in hot Recruitment!
- Short talk about community: how to build a game community?
- JSR303数据校验
- Google &huggingface| zero sample language model structure with the strongest ability
- Ie mode of selenium edge
- Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
- 进销存软件排行榜前十名!
猜你喜欢

Idea view View the class file idea Class folder

Selenium Edge的IE模式

港股今年最大IPO来了,660亿身家,坐在矿山上的“大王”

Auto - vérification recommandée! Les bogues MySQL ne font pas reculer les transactions, peut - être êtes - vous à risque!

Babbitt | metauniverse daily must read: meta, Microsoft and other technology giants set up the metauniverse Standards Forum. Huawei and Alibaba joined. NVIDIA executives said that they welcomed partic

2021-06-07

k8s--部署单机版MySQL,并持久化
Analysis and solution of connection failure caused by MySQL using replicationconnection

加快 yarn install 的三个简单技巧

建议自查!MySQL驱动Bug引发的事务不回滚问题,也许你正面临该风险!
随机推荐
How is it safe to open an account for futures? Which futures company has a relatively low handling fee for futures and is suitable for retail investors to open an account?
mysql主从只同步部分库或表的思路与方法
2021-06-03
Test article
How to ensure long-term stable operation of EDI system
Mysql数据库---日志管理、备份与恢复
中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
Hot Recruitment! The second Tencent light · public welfare innovation challenge is waiting for you to participate
After nine years at the helm, the founding CEO of Allen Institute retired with honor! He predicted that Chinese AI would lead the world
2021-06-07
掌舵9年,艾伦研究所创始CEO光荣退休!他曾预言中国AI将领跑世界
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
Analysis and solution of connection failure caused by MySQL using replicationconnection
2021-05-08
The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of the TCC mode
volatile~多线程下变量不可见
Golang-- judge whether the strings are equal
聚合生态,使能安全运营,华为云安全云脑智护业务安全
Résumé de la méthode de déduction de la force 513 - trouver la valeur du coin inférieur gauche de l'arbre
ts封装请求