unshift() Function is used to add a new element at the beginning of the array and shifts other elements to the right.
Let us say, we have a Array that contains four names, Mohan, Kriti, Philip and Salim. And we want to add the element Benny at the beginning of the Array.
<html>
<body>
<script>
var x = ["Mohan", "Kriti", "Philip", "Salim"]
x.unshift("Benny")
document.write(x)
</script>
</body>
</html>
So, all we have done is, used the unshift() method to add the name Benny at the beginning of the Array.
x.unshift("Benny")And what happens is Benny gets inserted at index 0 pushing all other elements to the right.