Javascript array pop() function

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:

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:

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

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.

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.

okay thanks, it has passed me.

A few things:

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

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.

thanks you, i have psssed it.

CONGRATS!!! =) You go!

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