Trigger condition based on iteration

So, I understand that for a single key-value based condition, we can easily create trigger conditions.
For example, in my response’s source, I have the following…

      "difference_by_days" : 0

In the above, I can just put a condition like…
ctx.results[0].hits.hits._source. difference_by_days > 0

If the above is true then I generate an alert and if it’s false, I don’t.

But, what about the cases where I have to loop through a dynamic sized array and along with each iteration that is made, I need to return true or false and based on a certain condition and for all those iterations where the condition was true, there should be an alert sent along with some data that was present in the variables during a particular iteration.