How to implement Array.prototype.unshift? JavaScript Interview Question | Problem Solving | JavaScript Polyfills
@Yomesh Gupta

Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.


In this question, the candidate needs to implement a function customUnshift that mimics the behaviour of Array.prototype.unshift method.

More about Array.prototype.unshift

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.


const array = [1, 2, 3];

array.unshift(4, 5);

// prints [4,5,1,2,3]


unshift(element0, element1)
unshift(element0, element1, /* … ,*/ elementN)


  • elementN

The elements to add to the front of the arr.

Return value

The new length property of the object upon which the method was called.


Start the timer, complete your solution, and test it against the testcases provided by the platform. Ideally, you should finish this question within 30 mins. Share your solution with us --

Loading IDE...