Manipulate Arrays With pop() problem

var ourArray = [1,2,3];

var removedFromOurArray = ourArray.pop();

// Setup

var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.

var removedFromMyArray=myArray[1];

myArray.pop();

its just showing this

myArray should only contain [["John", 23]] . :+1:t2:

You should use pop() on myArray . :-1:t2:

removedFromMyArray should only contain ["cat", 2] . :+1:t2:

Hi @Rosley

It would be a lot easier to help if you provided a link to the challenge.

@nibble
umm sure why not :smiley:

Hi!

pop() returns the removed item, so you gotta hand it over to where it should be stored, not exactly but in language somewhat like this:

the_removed_portion EQUALS the full array.pop()

Your solution works in terms of values, but it is actually a bit cheating. :slight_smile: What if your array has an unknown number of entries and you want to remove the last item? Then myArray[1] wouldnโ€™t work.

Best, Sebastian.

pop() function in javscript removes last element in array

i know and im doing it but it keeps showing that i am the wrong coding

Try this:

let removedFromArray = myArray.pop();

thanks a lot. @beiti

1 Like

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 (โ€™).

1 Like

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