im creating a function that will create a p element for every item in an array
const liArray = ["hello", "hi", "hello", "test", "hey"];
const parentElement= document.getElementById("myDiv");
const index1 = liArray.slice(-1);
const p = document.createElement("p");
p.innerHTML = "1. " + index1;
parentElement.appendChild(p);
const index2 = liArray.slice(-2, -1);
const p2 = document.createElement("p");
p2.innerHTML = "2. " + index2;
parentElement.appendChild(p2);
const index3 = liArray.slice(-3, -2);
const p3 = document.createElement("p");
p3.innerHTML = "3. " + index3;
parentElement.appendChild(p3);
const index4 = liArray.slice(-4, -3);
const p4 = document.createElement("p");
p4.innerHTML = "4. " + index4;
parentElement.appendChild(p4);
const index5 = liArray.slice(-5, -4);
const p5 = document.createElement("p");
p5.innerHTML = "5. " + index5;
parentElement.appendChild(p5);
so the result of this will be
1. hello
2. hi
3. hello
4. test
5. hey
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