Using JavaScript I would like to change the style of each <span> from an array of colors. Here is an example:
HTML:
<span>H</span>
<span>E</span>
<span>L</span>
<span>L</span>
<span>O</span>
JS:
colors=['red', 'orange', 'yellow', 'blue','green'];
[...document.querySelectorAll('span')].map( sp => {
sp.style.color = colors[0];
colors.shift();
});
Now my current thought is to spread my selection and use map so that I can iterate through each object. At the moment I am deleting elements in the colors as they are being used. I could also create an iterator to keep track of the colors so they do not get deleted. Assuming the number of objects and number of colors are the same I could also just step through with a for loop and set colors.
How can I accomplish this?