# Javascript array pop() function

**URL:** <https://forum.freecodecamp.org/t/javascript-array-pop-function/494001>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [January 24, 2022, 10:02pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001 "2022-01-24T22:02:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chijiokerichy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chijiokerichy/32/229620_2.png) [@chijiokerichy](https://forum.freecodecamp.org/u/chijiokerichy)\
**Post date:** [January 24, 2022, 10:02pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/1 "2022-01-24T22:02:11Z")

</div>

const myArray =[[“John”, 23], [“cat”, 2]];

i was ask to make myArray equals [[“John”, 23]];  
after using pop() function on myArray .

then make const removedFromArray equals [[“cat”, 2]];

**Your code so far**  
can’t solve this i need help

my code so far:

```javascript
const myArray= myArray.pop();

const removedfromArray=myArray.pop();

```

please i need help that code above didn’t pass me am stucked

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 OPR/78.0.4093.147`

**Challenge:** Escaping Literal Quotes in Strings

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [January 24, 2022, 10:09pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/2 "2022-01-24T22:09:32Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [January 24, 2022, 10:11pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/3 "2022-01-24T22:11:25Z")

</div>

> [@chijiokerichy](#):
>
> `const myArray= myArray.pop();`

Is this the first time that `myArray` is declared? If so, then having it on the right of the assignment operator doesn’t make sense. If `myArray` already exists, then you are redeclaring, which is invalid syntax.

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [January 24, 2022, 10:36pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/4 "2022-01-24T22:36:51Z")

</div>

> [@chijiokerichy](#):
>
> can’t solve this i need help

You didn’t link to the correct challenge.  
Also please go to your challenge and read the task again. You are calling `.pop()` twice but according to your explanation, you want it to do two different things with each call → so that can’t work.  
Also given how `.pop()` actually works, you propably only need to call it once.

---

<div class="post-metadata">

**Author:** ![chijiokerichy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chijiokerichy/32/229620_2.png) [@chijiokerichy](https://forum.freecodecamp.org/u/chijiokerichy)\
**Post date:** [January 25, 2022, 8:47am UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/5 "2022-01-25T08:47:20Z")

</div>

okay thanks, it has passed me.

---

<div class="post-metadata">

**Author:** ![medic1111](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/medic1111/32/246962_2.png) [@medic1111](https://forum.freecodecamp.org/u/medic1111)\
**Post date:** [January 26, 2022, 4:13am UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/6 "2022-01-26T04:13:00Z")

</div>

A few things:

1- Your array is declared is a const. Therefore, you cannot redeclare it. To pop it, you simply:

```auto
myArray.pop();

```

2- If you do that, you will remove the last nested array, leaving your original array with nothing but john, 23.

3- That means that when you create a removedFromArray and pop it again… the only thing  
it has available to pop is john,23 because you already popped the cat before.  
So you are technically popping TWICE.

- In simpler words, that first pop is unnecessary.

---

<div class="post-metadata">

**Author:** ![chijiokerichy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chijiokerichy/32/229620_2.png) [@chijiokerichy](https://forum.freecodecamp.org/u/chijiokerichy)\
**Post date:** [January 26, 2022, 4:18am UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/7 "2022-01-26T04:18:05Z")

</div>

thanks you, i have psssed it.

---

<div class="post-metadata">

**Author:** ![medic1111](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/medic1111/32/246962_2.png) [@medic1111](https://forum.freecodecamp.org/u/medic1111)\
**Post date:** [January 26, 2022, 4:52am UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/8 "2022-01-26T04:52:12Z")

</div>

CONGRATS!!! =) You go!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 27, 2022, 4:52pm UTC](https://forum.freecodecamp.org/t/javascript-array-pop-function/494001/9 "2022-07-27T16:52:31Z")

</div>

Closed on July 27, 2022, 4:52pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
