How to write JavaScript unshift and shift array methods from scratch
Dec 9, 2023 · 1 min read · unshift Add an element to the front of an array Array.prototype._unshift = function(...values) { const newArray = [...values, ...this] this.length = 0 this.push(...newArray) return this.length; }; const fruits = ['apple', 'mango', 'banana']...
Join discussion
