I have an Javascript array of indexes like so [0, 2]
And a bunch of paragraph elements like so
<div>
<p>some text</p>
<p>some more text</p>
<p>some sample text</p>
<p>some text here</p>
<p>some great text</p>
</div>
What would be a succinct way to add a css class to the paragraphs whose index appears in the array? In this case I expect a class to be added to first and third paragraphs.
Output expected:
<div>
<p class=“red”>some text</p>
<p>some more text</p>
<p class=“red”>some sample text</p>
<p>some text here</p>
<p>some great text</p>
</div>
:nth-child()......