Is there an existing function that finds the first array element that matches some general predicate?
$.fn.findFirstMatching = function(predicate) {
var result;
$.each(this, function(index, value) {
if (predicate(index, value)) {
result = {index: index, value: value};
}
});
if (result) {
return result;
}
};
If you use underscore.js, then you could use find method. It works even with jQuery objects storing collection of elements without problems.
But besides this additional (but small) library you need to write it by yourself.