Looking to just return one item at a time with a loop on an array in local storage, currently I have built a marquee with css to simulate a scrolling animation. The goal is to loop in a way that returns just one
element, then on the second loop, return the second item and so forth. Is this possible through setInterval or setTimeout? where the index is looped between delays or timeouts?
Is it possible to do this with a for loop? Or should I use something else? I specifically need the first item shown, then the second, exclusively and can't seem to properly articulate it enough as to find an answer
I've tried using the Queue class, but cant seem to get that to work either. This is the closest I can come up with as a working example.
Gif Exmaple
Code below
const marqueeMonthlies = () => {
insertMarquee.empty();
let marqueeMonthlyPlates = JSON.parse(localStorage.getItem('Monthly Plates'));
for (i = 0; i < marqueeMonthlyPlates.length; i++) {
insertMarquee.append(`
<div class="container" id="generatedMonthlyPlates">
<input type="text" width="100px" name="monthlyLicensePlate" id="${marqueeMonthlyPlates[i]}" class="licensePlate" placeholder="AB12345" value="${marqueeMonthlyPlates[i]}"/>
</div>
`)
}
}
startMonthlies.click((event) => {
event.preventDefault();
setInterval(marqueeMonthlies(),1000);
})
What would be the best way to go about that?
Someone mentioned use a generator function, but I have no idea how that would help me in this situation, given that I need to return each result as a singular license plate, and not groups of them.