当前位置:网站首页>JS traversal array (using the foreach () method)
JS traversal array (using the foreach () method)
2022-06-23 15:11:00 【Liujiayi_】
forEach() Method You need a function as an argument
- Functions like this , Created by us but not called by us , We call it a callback function
- If there are several elements in the array, the function will execute several times , Every time it is executed , The browser will traverse the elements
Passed in as an argument , We can define formal parameters , Read this
- The browser will be in the callback function Pass three parameters :
The first parameter , Is the element currently being traversed
The second parameter , Is the index of the element currently being traversed
The third parameter , Is the array being traversed
<!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 = [" The Monkey King ", " Pig eight quit ", " The sand monk ", " Tang's monk ", " Bones jing "];
arr.forEach(function (value, index, obj) {
console.log(value);
});
</script>
</body>
</html>

边栏推荐
- AI intelligent robot saves us time and effort
- Arrays in JS
- KDD'22「阿里」推荐系统中的通用序列表征学习
- MySQL create and manage tables
- List query sorting parameter processing
- 2021-05-08
- Volatile~ variables are not visible under multithreading
- 【云驻共创】制造业企业如何建设“条码工厂”
- Auto - vérification recommandée! Les bogues MySQL ne font pas reculer les transactions, peut - être êtes - vous à risque!
- Gartner最新报告:低代码应用开发平台在国内的发展
猜你喜欢
随机推荐
加快 yarn install 的三个简单技巧
MySQL create and manage tables
力扣解法汇总513-找树左下角的值
JS里的数组
golang--判断字符串是否相等
腾讯云服务器发送邮件失败
Pop() element in JS
Force deduction solution summary 513- find the value of the lower left corner of the tree
Raspberry PI installing the wiring pi
打印内存站信息
SQL注入漏洞(原理篇)
建議自查!MySQL驅動Bug引發的事務不回滾問題,也許你正面臨該風險!
Mysql双主配置的详细步骤
JSR303数据校验
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
[cloud based co creation] intelligent supply chain plan: improve the decision-making level of the supply chain and help enterprises reduce costs and increase efficiency
HCIA network foundation
2021-04-15
[pyside2] pyside2 window is on the top of Maya (note)
[opencv450] salt and pepper noise demo
![[普通物理] 半波损失 等厚与等倾干涉](/img/66/e0acce623092ecd38e59e38867521d.png)








