I am working with a JavaScript array that looks like this:
const colors = ['blue', 'red', 'green'];
If I have a number ranging from 0
to Infinity
, how can I retrieve a color value in the following pattern:
colors[0] === 'blue';
colors[1] === 'red';
colors[2] === 'green';
colors[3] === 'blue';
colors[4] === 'red';
colors[5] === 'green';
// …
Once all elements of the array have been accessed, retrieving colors based on numerical values should cycle through the array sequentially.