重學(xué)ES系列之新增的幾個循環(huán)方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新增的幾個循環(huán)方法</title>
</head>
<body>
<script>
let arr = [1,2,3,4];
for (const i in arr) {
console.log(i);//0,1,2,3
}
// for in 默認(rèn)循環(huán)的是坐標(biāo)
for (const item of arr) {
console.log(item);//1,2,3,4
}
// for of 默認(rèn)循環(huán)的是每一項(xiàng)的內(nèi)容
arr.forEach((item,i)=>{
console.log(item,i);
})
</script>
</body>
</html>
作者:Vam的金豆之路
主要領(lǐng)域:前端開發(fā)
我的微信:maomin9761
微信公眾號:前端歷劫之路