<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The unshift() Method</h2>
<p>The unshift() method adds new elements to the beginning of an array:</p>
<p id="workingcode1"></p>
<p id="workingcode2"></p>
<script>
const hero = ["Antman","Spiderman","Superman","Wonderwoman"];
document.getElementById("workingcode1").innerHTML = hero;
hero.unshift("Ironman");
document.getElementById("workingcode2").innerHTML = hero;
</script>
</body>
</html>
Output
JavaScript Arrays
The unshift() Method
The unshift() method adds new elements to the beginning of an array:
Antman,Spiderman,Superman,Wonderwoman
Ironman,Antman,Spiderman,Superman,Wonderwoman
Use of Unshift() method JavaScript
admin Changed status to publish December 19, 2023