Adding Elements in an Array

Adding elements at the start using unshift()

One or multiple elements can be added at the start of the array using the unshift() subroutine.

unshift() prepends passed elements at the front of an array. Note that the list of elements is prepended as a whole so that the prepended elements stay in the same order. All numerical array keys will be modified to start counting from 0.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy