freeCodeCamp Challenge Guide: Manipulate Arrays With unshift()

Manipulate Arrays With unshift()


Hints

Hint 1

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
7 Likes

This does not work, and I cannot figure it out

12 Likes

Make sure that you are unshifting an array and not each item, example:

var myArray = ['Hello', 'World']; myArray.unshift(['More stuff', 60]); console.log(myArray); // [['More stuff', 60], 'Hello', 'World']

13 Likes

this worked for me myArray.unshift([“Paul”,35]);

25 Likes

i am stuck in this one. it says to append [“Paul”,35] in the beginning.
below it says myArray should now have [[“Paul”, 35], [“dog”, 3]] so we have to use .shift() as well? to remove [“John”, 23]?

any one?

14 Likes