> 循环遍历是一个比较常用的功能,这里特此介绍
[TOC]
## 常规for
~~~
let list = ['wk', 'lj', 'wx'];
for (var i = 0; i < list.length; i++) {
console.log("index: "+ i + ", val:" + list[i])
}
~~~
## for in
> 循环出来的变量是数组下标
~~~
let list = ['wk', 'lj', 'wx'];
for (let index in list) {
console.log("index: "+ index + ", val:" + list[index])
}
~~~
## for of
> 循环出来的变量是数组值
~~~
let list = ['wk', 'lj', 'wx'];
for (let val of list) {
console.log(val)
}
~~~
## array.forEach()
~~~
let list = ['wk', 'lj', 'wx'];
//list.forEach(function(val, index, arr){
// console.log("index: "+ index + ", val:" + val)
//})
list.forEach(function(val){
console.log("val:" + val)
})
~~~