Dark Launch

JavaScript concat document.querySelectorAll

Merge two lists of elements returned by document.querySelectorAll().

Given the following html, select the div and list items.

HTML
<div>A</div>
<ul>
    <li>B</li>
    <li>C</li>
    <li>D</li>
</ul>
Javascript
var someNode = document.querySelector('div');
var moreNodes = document.querySelectorAll('li');
var combined = [someNode].concat(Array.prototype.slice.call(moreNodes));
console.assert(combined.length === 4);

The combined variable now contains [div, li, li, li].