freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-javascript/manipulate-arrays-with-unshift/index.md

424 B

title
Manipulate Arrays With unshift()

Manipulate Arrays With unshift()

While push() added elements to the back of the array, unshift() adds them to the front. All you have to do is:

var arr = [2, 3, 4, 5];
arr.unshift(1); // Now, the array has 1 in the front