I want to create a repeating pattern to color the background, but once i
exceeds colors.length
, the background color stops changing because, for example, colors[3]
does not exist. I need colors[i]
to start back at 0 until the first loop is complete.
const arr = document.getElementById('collection');
const colors = ['#FFC6C6', '#A4BDFF', '#F9F9F9'];
for (let i = 0; i < arr.children.length; i++) {
arr.children[i].style.background = colors[i];
}