Reputation: 22959
I have this loop right here:
function sendBackOne() {
var selected = paper.project.selectedItems;
for (var i = 0; i < selected.length; i++) {
console.log(selected[i].name);
}
where selected is an array with items that i iterate over.
One of the items has a ''name'' property set to ''something''. I don't want to go over that element in my loop,i need to disregard it.
How would i go about doing that?
The best way i can figure is writing an IF/ELSE statement in the loop to check the name and if it's not ''something'' i do what i need to do.
Is this the best way?
Upvotes: 2
Views: 74
Reputation: 239573
Yes it is. You can also use a continue
statement like this
var selected = paper.project.selectedItems;
for (var i = 0; i < selected.length; i++) {
if (selected[i].name === "something") continue;
... // Whatever you wanted to do, goes here
}
Upvotes: 1
Reputation: 104785
Simple:
if (selected[i].name == "something")
continue;
Use continue
to head to the next iteration.
Upvotes: 3