how to skip elements in foreach loop

后端 未结 7 1822
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 17:56

I want to skip some records in a foreach loop.

For example, there are 68 records in the loop. How can I skip 20 records and start from record #21?

7条回答
  •  清歌不尽
    2020-12-05 18:51

        array.forEach(function(element,index){
            if(index >= 21){
                //Do Something
            }
        });
    

    Element would be the current value of index. Index increases with each turn through the loop. IE 0,1,2,3,4,5; array[index];

提交回复
热议问题