14. Heterogeneous arrays


Oops, try again. Make sure you have at least four elements in myArray.

Not too sure what i'm supposed to be doing :confused:

Replace this line with your code. 
var myArray = [45, true, "hello", Object];

var Object = {
    rain: 'yes',

    clouds: 'no',

    bats: 'plenty',

    cats: 'not that high',

myArray = [Object];


That is a no-no. Object is the root class of everything in JavaScript (with exception to primitives). We would never give this name to a variable. If the interpreter didn't catch it, we might well have crashed JavaScript.

Use generic or descriptive variable names that are not reserved words or JavaScript special classes.

var myObject = {};

will work, but it has to be defined before the array definition references it.

Another no-no. Why would you want to destroy your array?

var myObject = {
    rain: 'yes',
    clouds: 'no',
    bats: 'plenty',
    cats: 'not that high'
var myArray = [45, true, "hello", myObject];

Now the next trick will be accessing the object in the array. Recall that it is not a named object in the array, but an element at a fixed index position, and only a reference to the real object in memory; its data is not stored here.

console.log(myArray[3].rain)    // yes


thanks mate. working fine now


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