# freeCodeCamp Challenge Guide: Manipulate Arrays With unshift()

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 7, 2016, 8:49pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239 "2016-07-07T20:49:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 7, 2016, 8:49pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/1 "2016-07-07T20:49:10Z")

</div>

# [Manipulate Arrays With unshift()](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/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:

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

```

---

<div class="post-metadata">

**Author:** ![ozwald71](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ozwald71/32/18979_2.png) [@ozwald71](https://forum.freecodecamp.org/u/ozwald71)\
**Post date:** [October 25, 2016, 3:21am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/2 "2016-10-25T03:21:45Z")

</div>

> [@camperbot](#):
>
> myArray.unshift(‘Paul’);

This does not work, and I cannot figure it out

---

<div class="post-metadata">

**Author:** ![StrongeLeeroy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/strongeleeroy/32/164548_2.png) [@StrongeLeeroy](https://forum.freecodecamp.org/u/StrongeLeeroy)\
**Post date:** [October 27, 2016, 10:46am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/3 "2016-10-27T10:46:47Z")

</div>

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']`

---

<div class="post-metadata">

**Author:** ![Naiguy1](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@Naiguy1](https://forum.freecodecamp.org/u/Naiguy1)\
**Post date:** [July 26, 2017, 4:28pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/5 "2017-07-26T16:28:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alihassan90](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alihassan90/32/161561_2.png) [@alihassan90](https://forum.freecodecamp.org/u/alihassan90)\
**Post date:** [July 27, 2017, 4:34pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/6 "2017-07-27T16:34:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 10, 2019, 1:20am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/8 "2019-08-10T01:20:25Z")

</div>

Opened on August 10, 2019, 1:20am UTC



---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2025, 12:00pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-manipulate-arrays-with-unshift/18239/9 "2025-01-07T12:00:02Z")

</div>

Closed on January 7, 2025, 12:00pm UTC


