Home
<!DOCTYPE html> <html> <body> <h1>Demo: Accessing Array Elements in JavaScript</h1> <p id="p1"></p> <p id="p2"></p> <p id="p3"></p> <p id="p4"></p> <p id="p5"></p> <p id="p6"></p> <p id="p7"></p> <p id="p8"></p> <p id="p9"></p> <p id="p10"></p> <p id="p11"></p> <script> let numArr = [10, 20, 30, 40, 50]; document.getElementById("p1").innerHTML = numArr.at(0); document.getElementById("p2").innerHTML = numArr.at(1); document.getElementById("p3").innerHTML = numArr.at(2); document.getElementById("p4").innerHTML = numArr.at(3); document.getElementById("p5").innerHTML = numArr.at(4); document.getElementById("p6").innerHTML = numArr.at(-1); document.getElementById("p7").innerHTML = numArr.at(-2); document.getElementById("p8").innerHTML = numArr.at(-3); document.getElementById("p9").innerHTML = numArr.at(-4); document.getElementById("p10").innerHTML = numArr.at(-5); document.getElementById("p11").innerHTML = numArr.at(-6); </script> </body> </html>
Result: