How can I exit from $.each loop when a condition is met? I don’t want to iterate the collection further.
$(vehicles).each(function() {
if (this["@id"] === vehicleId[0]) {
vehicle = this;
}
});
I tried with break; & return; statement but it looks the execution doesn’t not stop at that point. Any idea would be greatly appreciated.
Returning false is the equivalent of breaking out of a $.each loop. So in your example: