Remove item[i] from jQuery each loop

后端 未结 7 1980
别跟我提以往
别跟我提以往 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:43

    If you want to remove an element from array, use splice()

    var myArray =['a','b','c','d'];
    var indexToRemove = 1;
    // first argument below is the index to remove at, 
    //second argument is num of elements to remove
    myArray.splice(indexToRemove , 1);
    

    myArray will now contain ['a','c','d']

提交回复
热议问题