Photoshop CC 2017. Using this loop to delete paths one by one results in some paths (out of 8) being deleted only:
for(i = 0; i < app.activeDocument.pathItems.length; i++) {
alert(i)
app.activeDocument.pathItems[i].remove();
}
The length gets reported as being 8. However alert(i) only shows 4 times. All the paths get removed only if running the loop multiple times. I’m deleting them one by one because I want to keep a path with a certain name. Any ideas?
2
Answers
You are changing
pathItems
as you loop through it. When you delete itemi
there will be a new item at positioni
that you skip.If you do the loop backwards it won’t cause any problems
You can use
pathItems.removeAll()
in this case.