14. please help!


#1

this is my code:

var myArray = [10, true, "test",];

var space = {
age: 18,
name: 'jeff'
};

myArray = [space];

//NOTE THAT THIS DOES NOT CORRESPOND TO MY REAL LIFE AGE AND NAME!


14 Heterogeneous arrays
#2

@dilbertron,
The Instructions
Create an array, myArray.

  • Its first element should be a number, var first = 1;
  • its second should be a boolean, var second = true;
  • its third should be a string, var third = "aString";
  • and its fourth should be... an object! var fourth = { propertyKey: "associatedValue" }

    var myArray = [first,second,third,fourth];
    console.log( myArray );

=====================================

As you did it, could have functioned
if you had appended the space Object
using the push() method
like

myArray.push(space);
console.log( myArray );

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push


#3

Why do it call with " ", { } and [ ] ?
Is there some syntax' hucks to avoid them?


#4

Or simply just define an object at first then just gives values for the others, here is my code

var charmender = new Object();
charmender.type = "fire";
var myArray = [12,true,"Pokemon,charmender]
console.log(myArray);


#5

@devninja48662,

var myArray = [12,true,"Pokemon",charmender]

#6

use a 'for' loop instead of the regular console.log to make it more challenging and still yes the object notation will still be in curly braces.


#7

Try this one

var myObj = {
type: 'fancy',
disposition: 'sunny'
};
var myArray=[43,true,"sdf",myObj];
for(i=0;i<=3;i++)
{console.log(myArray[i]);}