Heterogeneous Arrays?


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/javascript-beginner-en-9Sgpi/3/1?curriculum_id=506324b3a7dffd00020bf661#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

It keeps telling me to make sure my array should have at least 4 elements in my array. I’m not sure what it means by that?Not sure what I did wrong with the code maybe its how I have it structured?



var myArray = [1, 'Thing',]
var bool1 = true;
myArray = [bool1];
var myObj = {
    name: 'Nat',
    thing: 'Stuff'
}
myArray = [[myObj,][bool1]];



https://www.codecademy.com/courses/javascript-beginner-en-9Sgpi/3/1?curriculum_id=506324b3a7dffd00020bf661#


#2

If you read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
and you look at the page,
on the left-hand side you have column
which is splitted in Properties and Methods

Of the Properties you will often use Array.length
like

var myArray = ['a',"B",3];
console.log( myArray.length);

will give you the result 3
So you can now say this Array has 3 Elements
or others will say this Array has 3 items

============================================
Now the next thing you should now

If you create an =Array=
the Javascript Interpreter add the Properties
thus with

var myArray = [];
console.log( myArray.length );

will give a result of 0 zero which expresses an Array-Index of
You can now say this array has =zero= Items
and first free-Index is =zero=

So if you want to add the first Element/Item
you will use an Index of =zero=
like
myArray[0] = “First string-Element”;
myArray.length is now 1 one

So if you want to access the first Item
you will have to use an Index-nr of =zero=

===============================================
Back to the page of =the Book= describing the Array…
Under the Methods you will have a lot of functions which you can use on the Array-Object…

Now create an array of 4 Elements…


#3

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