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

JavaScriptBeginner
281
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.

InternationalDomestic

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

More about Array.prototype.push

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

Examples

const array = [1, 2, 3];

array.push(4, 5);

// prints [1,2,3,4,5]
console.print(array);

Syntax

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

Parameters

  • 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.

Submission

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 -- https://twitter.com/devtoolstech

Loading IDE...