I'd like to flatten a DOM tree into an Array.
The result should include the root as the first entry.
Plain JS solution is preferred.
What's the fastest way to achieve that?
HTML structure example:
<div class="tested-root">
<span></span>
<span></span>
<div>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
</div>
</div>
The output expected to be:
[div.tested-root, span, span, div, span, span, div, span, span] or alike (this one is DFS, but doesn't really matter for sake of this question).
From the three methods below which is the fastest:
querySelectorAllNodeIteratorTreeWalker