I’ve built an array of table elements matching a specific criterion using querySelectorAll(), but I’d like to conditionally create a new, separate array containing the first child of the first child of each of those elements.
However, I’m not sure how to do this.
My array currently looks like this:
var arr = [
<table class="matchedCriterion">…</table>,
<table class="matchedCriterion">…</table>
];
Is there a way for me to run querySelector() or querySelectorAll() on each element, matching what I want using :first-child:first-child
The
.mapfunction lets you build a new Array from another array.If your
arris not actually an array, then do this.Be aware that this will get text nodes if those happen to be the first child. If you want elements only, use
.firstElementChildinstead of.firstChild.