Home
<!DOCTYPE html> <html> <body> <h1>Demo: Add Array Elements in JavaScript</h1> <p id="p1"></p> <p id="p2"></p> <p id="p3"></p> <script> let cities = ["Mumbai", "New York", "Paris", "Sydney"]; document.getElementById("p1").innerHTML = cities; cities.unshift("Delhi"); //adds new element at the beginning document.getElementById("p2").innerHTML = cities; cities.unshift("London", "Pune"); //adds new element at the beginning document.getElementById("p3").innerHTML = cities; </script> </body> </html>
Result: