javaScript07-流程控制-foreach

for、while、dowhile、if语句和Java差不多

JS的foreach语句:

<script>

    let num=[22,33,55,44];

    num.forEach(function (x){
        console.log(x);
    })

    num.forEach(function (x,index,self){
        console.log('元素:'+x+',索引位:'+index+',数组本身:'+self);
    })


</script>

function() 三个参数:
  • 第一个参数,ele,当前元素
  • 第二个参数,index,当前索引位
  • 第三个参数,self,就是数组本身
posted @ 2021-11-10 13:27  卡卡发  阅读(41)  评论(0)    收藏  举报