当前位置:网站首页>数组对象方法 常用遍历方法&高阶函数
数组对象方法 常用遍历方法&高阶函数
2022-07-24 18:08:00 【无围之解】
三、常用遍历方法&高阶函数
1.for()
最常用的for循环,经常用的数组遍历,也可以遍历字符串。
const arr = [1, 2, 3]
const str = 'abc'
for (let i = 0; i < arr.length; i++) {
console.log(arr[i])
console.log(str[i])
}
2.while() / do while()
while、do while主要的功能是,当满足while后边所跟的条件时,来执行相关业务。这两个的区别是,while会先判断是否满足条件,然后再去执行花括号里面的任务,而do while则是先执行一次花括号中的任务,再去执行while条件,判断下次还是否再去执行do里面的操作。也就是说 do while至少会执行一次操作.
while(条件){
执行...
}
------------
do{
执行...
}
while(条件)
3.forEach()
拷贝一份遍历原数组。
return无法终止循环。不过可以起到continue效果。本身是不支持的
continue与break语句的我们可以通过some和every来实现。
边栏推荐
猜你喜欢

PXE高效批量网络装机

0630~职业素养课

Use of jumpserver

05mysql lock analysis

Use prometheus+grafana to monitor MySQL performance indicators

Common methods of number and math classes

Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research

Go language file operation

After separation, the impression notes are still difficult to live, but there are many coquettish operations

C language to achieve a static version of the address book
随机推荐
Wu Enda writes: how to establish projects to adapt to AI career
干货|值得收藏的三款子域名收集工具
Dry goods | three sub domain name collection tools worth collecting
获取同程(艺龙)酒店数据
Detailed explanation of ansible automatic operation and maintenance (V) the setting and use of variables in ansible, the use of jinja2 template and the encryption control of ansible
继承与派生
1688/ Alibaba searches new product data by keyword API instructions
How to follow the "low coupling" design principle?
Opencv picture rotation
Can CSC open an account for domestic futures? Is it safe?
0623~放假自习
Get the original data API on 1688app
【obs】视频、音频编码与rtmp发送的配合
T245982 「KDOI-01」醉花阴
C语言自定义类型讲解 — 联合体
[OBS] cooperation between video and audio coding and RTMP transmission
redis集群的三种方式
0614~放假自习
Quickly complete the unit test junit4 setting of intelij idea
C language custom type explanation - structure