Basic JavaScript - Manipulate Arrays With unshift Method

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// Setup
const myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line
myArray.unshift[("Paul" , 35)];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Manipulate Arrays With unshift Method

Link to the challenge:

unshift is a method (or function) and thus you must invoke it with parens. You have invoked it with square brackets, which is a syntax error.

took away the sq brackets just added parentheses still didn’t get the go ahead.

Well, you are adding an array to the beginning of myArray, so you will need square brackets to do that. If you still need help then please post your most current code in here so we can see what you did.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

myArray.unshift("Paul", 35);

new code

So you are invoking unshift correctly now, but you aren’t adding what the instructions asked you to add to the beginning of myArray.

“Add ["Paul", 35] to the beginning of the myArray

sir no offense but I am very confused , can you please display how it’s done.

Instead, please explain what you are confused about. You are calling the unshift method correctly. You just aren’t adding what the instructions are asking you to add.

“Add ["Paul", 35] to the beginning of the myArray

What do you not understand about these instructions?

wow I had the whole thing backwards, I got it now haha thank you for your cooperation and patience.

2 Likes

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