title: is there a faster way to display every index of an array
body: <p>im creating a function that will create a p element for every item in an array</p>
  <pre class="lang-js prettyprint-override"><code>  const liArray = [&quot;hello&quot;, &quot;hi&quot;, &quot;hello&quot;, &quot;test&quot;, &quot;hey&quot;];
  
    const parentElement= document.getElementById(&quot;myDiv&quot;);
    const index1 = liArray.slice(-1);
    const p = document.createElement(&quot;p&quot;);
    p.innerHTML = &quot;1. &quot; + index1;
    parentElement.appendChild(p);
    
    const index2 = liArray.slice(-2, -1);
    const p2 = document.createElement(&quot;p&quot;);
    p2.innerHTML =  &quot;2. &quot; + index2;
    parentElement.appendChild(p2);
    
    const index3 = liArray.slice(-3, -2);
    const p3 = document.createElement(&quot;p&quot;);
    p3.innerHTML =  &quot;3. &quot; + index3;
    parentElement.appendChild(p3);
     
    const index4 = liArray.slice(-4, -3);
    const p4 = document.createElement(&quot;p&quot;);
    p4.innerHTML =  &quot;4. &quot; + index4;
    parentElement.appendChild(p4);
   
    const index5 = liArray.slice(-5, -4);
    const p5 = document.createElement(&quot;p&quot;);
    p5.innerHTML =  &quot;5. &quot; + index5;
    parentElement.appendChild(p5);
  </code></pre>
  <p>so the result of this will be</p>
  <pre><code>1. hello
  2. hi
  3. hello
  4. test
  5. hey
  </code></pre>
  <p>and im wondering if there is any faster way to do it instead of manually slicing the array and creating elements like that which takes a lot of time especially if there is many items in the array</p>