Remove item[i] from jQuery each loop

后端 未结 7 2001
别跟我提以往
别跟我提以往 2020-12-15 03:05

How do I remove an item[i] from items once it reaches in:

$.each(items, function(i) {
    // how to remove this from items
});
7条回答
  •  误落风尘
    2020-12-15 03:35

    As mentioned by @lonesomday above (I simply couldn't add this in a comment) grep is for Arrays, but you could insert your selector inside grep:

    var items = $.grep($(".myselector", function (el, i) {
      return (i===5) ? false : true;
    };
    

    This would store all elements found using $(".myselector")in ìtems` leaving out the item at the 6th position (the list is 0 indexed, which makes "5" the 6th element)

提交回复
热议问题