$.each() index start number in jQuery

前端 未结 8 1982
慢半拍i
慢半拍i 2021-01-05 02:28

How do I start jQuery $.each() index from 1 instead of 0?

I am using .each function to populate select box. So here I want to populate options in the se

8条回答
  •  忘掉有多难
    2021-01-05 02:55

    $.each

    So try

    $.each(obj, function(i, elem) {
        if (i === 0) return;
        // do stuff
    });
    

    Alternatively rewrite your code so its so indexes and data start at 0. JavaScript is interally 0 based rather then 1 based like Matlab and some other languages.

提交回复
热议问题