I would like to ask some logic question here.
Let say I have a for loop in javascript to remove the whole items:-
var i = 0;
for (i=0;i<=itemsAll;i++) {
removeItem(i);
}
I do not want to remove item when i = current = e.g. 2 or 3.
how do I or where do I add a if-else statement in this current for loop?
Please help, anyone?
Iterate over it in reverse order and only remove the items which does not equal the current item.
I probably should have stated the reason for the reverse loop. As Hans commented, the loop is done in reverse because the ‘removeItem’ may cause the remaining items to be renumbered.