1. 24
    Cycle Through an Array of Values with the Modulus Operator
    7m 15s

Cycle Through an Array of Values with the Modulus Operator

InstructorAndy Van Slaars

Share this video with your friends

Send Tweet

We often need to move in one direction or another in a JavaScript array to focus on one value at a time. When we hit an upper or lower bound, it's convenient to have the referenced index jump to the other end of the array so we can keep cycling through in that same direction. In this lesson, we'll apply this to a React UI, allowing the UI to "jump" to the beginning of the array when we hit "next" at the end of the array, and to jump to the last item in the array when moving "back" and we hit the lower bound of the array and we'll do it by taking advantage of the % (modulus) operator.