Error - It looks like your first two rows are the same length. Make them different!


Can I get another set of eyes on this? I can't figure out why I am getting the error.

var object = new Object();

object["name"] = "noName";

var newArray = [ 
    [ [1,"test",12,12,12,],
        [1,object,2,3,4,5,6,7] ],
    [ [true, 10],
        ["test","test"] ] 


Can you please provide a screenshot of your assignment so that I can see what is that you need to do in this assignment.



Ok, so you need to make a new array called newArray and save in it 2 more arrays that have different length.

As an example in your assignment:

var newArray = [[1,2,"hey"], [2]];

You have 2 arrays saved inside newArray that are different sized.
1. nested array has 3 elements, and 2. nested array has 1 element.

And one of them must contain an object. So it can be written this way:

var newArray = [[1,"string",{object_key:"object_value"}],[5, "second string in second array"]];

Or just maybe an empty object ? Like this -> {}


I tried having just two arrays instead of having two nested arrays but it kept saying I was missing a row.

My first two rows- what are the first two rows? Also don't I have an object in my arrays?

What do U mean one has 3 elements and the other has one? I meant each nested array to have different amounts, in this case 5, 8 & 2, 2. Maybe he 2, 2 is the problem? Or not having an object in the second nested array.

I tried something like below and got an error saying I was missing rows.

newArray = [ [1,"string", object], [1,2,"string", true, 1,2,3] ];


Lets read out what the assignment wants. Reading from the screenshot you posted above.

  1. We need to create a 2D array, that's jagged and jagged = array of arrays, so it means it is array filled with other arrays and that nested arrays does not have the same length.

var aList = [[1,4,2],[7]];

So the aList is an array made of 2 arrays.
[1,4,2] array has a length of 3 elements and [7] array has a length of 1 element.

So all in all aList is 2D array and jagged .

aList is an example of 2D array, just maybe your assignment wants a little bit different look of your 2D array like:

var newArray = [

Note that we have 1 object nested inside first nested array, even I don't think that is must for completing the assignment.


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