What is wrong with my code?


#1


I am on Arrays and Objects in JS section 15.multidimensional arrays


It says I dont have 2 rows in my newArray but i do.

Oops, try again. It looks like newArray has fewer than two rows. Your array should be 2D!


var newArray = [ [1, 2,], [3] ]
var me = new Object();
me.name = "Joshua";
me.age = 14
newArray = [me];


#2

It does have two rows until you overwrite it in the last line.

If you wish to append the array, there are two ways you can do this...

  1. newArray[newArray.length] = me;
  2. newArray.push(me);

Well, three, actually. The above appends the array, the following prepends the array:

  1. newArray.unshift(me);

Examples

newArray.push(me);
console.log(newArray);

// [ [1, 2], [3], { name: 'Joshua', age: 14 } ]

newArray.unshift(me);
console.log(newArray);

// [ { name: 'Joshua', age: 14 }, [1, 2], [3] ]

#3

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