Unshift method to add element to an arrayWe can add elements at the beginning of an array by using unshift() method. Here is the general syntax for using unshift() method.
We have seen how to add element at the end of an array by using push() method.Here scripts is our array and we are adding two new elements VBScript and Perl at the beginning of this array by using unshift() method. Here is the complete code for unshift()
The above code will add VBScript and Perl at the end of the array and display the full list.
Output is here
unshift with key and valueArray key are re -indexed after using unshift() to add elements.
Output is here
This article is written by plus2net.com team.
![]() |
![]() |