snipt

Ctrl+h for KB shortcuts

JavaScript

NodeLists to arrays

1
2
3
4
//convert NodeLists into arrays
var myList = document.querySelectorAll('.ditemItemDisplayTemp');
var myArray = Array.prototype.slice.call(myList, 0);
myArray.slice(2)
https://snipt.net/embed/d08af46b06db9fbee5c4f43a50b97b2f/
https://snipt.net/raw/d08af46b06db9fbee5c4f43a50b97b2f/
d08af46b06db9fbee5c4f43a50b97b2f
js
JavaScript
4
2016-09-19T05:04:02
True
False
False
/api/public/snipt/27972/
nodelists-to-arrays
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">//convert NodeLists into arrays</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">myList</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelectorAll</span><span class="p">(</span><span class="s1">&#39;.ditemItemDisplayTemp&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">myArray</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">myList</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">myArray</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> </span></pre></div> </td></tr></table>
arrays, javascript, nodelists
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.