当前位置:网站首页>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>

边栏推荐
猜你喜欢
随机推荐
Helm 基础入门 Helm介绍与安装
2021-05-22
How can genetic testing help patients fight disease?
AI intelligent robot saves us time and effort
Tencent ECS failed to send email
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-05-22
中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
[普通物理] 光的衍射
The team of China University of Mines developed an integrated multi-scale deep learning model for RNA methylation site prediction
这届文娱人,将副业做成了主业
MySQL create and manage tables
巴比特 | 元宇宙每日必读:Meta、微软等科技巨头成立元宇宙标准论坛组织,华为、阿里加入,英伟达高管称欢迎来自加密世界的参与者...
JS里的数组
Uniswap acquires genie, an NFT transaction aggregator. Will the NFT transaction market change?
乐高宣布涨价,炒家更嗨皮了
SFOD:无源域适配升级优化,让检测模型更容易适应新数据(附论文下载)
SQL注入漏洞(原理篇)
Introduction to helm basics helm introduction and installation









