Tell us what’s happening:
Your code so far
// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]
// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();
// Only change code below this line.
myArray.unshift("Paul", 35);
console.log(myArray)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift
Your unshift is adding one string and one number.
You want to add an array which contains the string and the number.
myArray variable is reference to an two dimensional array, basically an array of arrays.
can you give me an example?
First you have an array which contains arrays [ [ " " ],[ " " ],[ " " ] ] called two dimensions array.
Example :
let arrayOfArrays = [['string 1'], ['string 2', 55]];
Example above is an array which has two children arrays (or nested).
First child array contains a string ‘string 1’ second child contains a string and a number ‘string 2’ and 55.
To add another child array with a string and a number, we use unshift method which will add content at the beginning of the array.
arrayOfArrays.unshift(['string 3', 44]);
Output:
//[ ["string 3", 44] , ["string 1"] , ["string 2", 55] ];
To just add to the parent array a string and a number.
arrayOfArrays.unshift('string last', 44);
Output:
//[ "string last", 44 , ["string 1"] , ["string 2", 55] ];
You tried myArray.unshift(“Paul”, 35) and you want myArray.unshift([“Paul”, 35]);
See the difference?
yes, thank you very much. the examples are great