var div = document.querySelectorAll('div'); for(var i = 0; i < div.length; i++) { div[i].setAttribute('data-index', i); } <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> There is such a code, at the moment the indices are assigned in a row, i.e. 0, 1, 2, 3, 4, 5, 6
How to make indexes assigned in such a way 0, 1, 2, 3, 0, 1, 2, 3
Those. maximum index = 3, if the maximum is reached, then start with 0
i % 4........ - Alexey Ten[...document.querySelectorAll('div')].forEach((div, i) => div.dataset.index = i % 4);- yar85 1:27 pm