Manipulate Arrays With unshift() dog, 3

I don’t know what to do about dog, 3. How do you edit it if it’s already been precoded in in the exercise? The result should be [[“Paul”, 35], [“dog”, 3]]. What am I doing wrong here?

myArray.unshift(’[“Paul”, 35]’);

// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
// ourArray now equals ["Happy", "J", "cat"]

// Setup
var myArray = [["John", 23], ["dog", 3]];

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

You need to trace back a bit and redo all the array\objects lessons,

On this line you are adding string at start of myArray, not array element.

var someVar = '["Paul", 35]'; // this is actually a string with content of ["Paul", 35], because it is placed between '
var someVar2 = ["Paul", 35]; // this will be array because it starts with [, telling interpreter it is array
1 Like

This will not work. You have made that a string, remove the quotes around the parenthesis, that’s an array.
I don’t know what’s the instructions of the challenge, but that would be a big thing to fix

1 Like

The error lies on the unshift() call, you don’t need to use any quotes to surround the array.

Correct code:

myArray.unshift(["Paul", 35});
1 Like