Skip to content

Instantly share code, notes, and snippets.

@djaney
Last active August 29, 2015 14:06
Show Gist options
  • Save djaney/93c0deec762699ae29da to your computer and use it in GitHub Desktop.
Save djaney/93c0deec762699ae29da to your computer and use it in GitHub Desktop.
// #1 - iterate only if no delete
for(var i=0 ;i<items.length;){
if(items[i].forDelete){
items.splice(i,1);
}else{
i++;
}
}
// #2 - iterate backwards
for(var i=items.length-1;i>=0;i--){
if(items[i].forDelete){
items.splice(i,1);
}
}
// #3 - decrement after iterate
for(var i=0 ;i<items.length;i++){
if(items[i].forDelete){
items.splice(i,1);
i--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment