The code below assumes that each item should has two attributes: unique id and value field. Due to boolean comparison operator we can get an appropriate element.
- Check if current index in iteration is not equal to collection.length, otherwise - specify index to 0.
- Increase current index by 1.
- Check if current element has value. If not - do 2nd step, if yes - return it and break loop.