I am facing a challenge where I need to create an array of IDs for each element in an existing array whose size is unknown. The twist here is that every set of four elements should have the same ID.
As an illustration, if the original array (let's call it array1) contains 20 items, the new array would look like this: [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]
I attempted to achieve this using a for loop but struggled with how to assign IDs to every four elements without overriding them during iteration.
for(let i = 0; i < itemlist.length; i++) {newArray[i] = i; newArray[i] = i;newArray[i] = i;newArray[i] = i;}