Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Create an Array of Objects

Inside the array literal, add three object literals. In other words, the objects array should have three values. Each ob

I am not sure what they mean by "Inside the array literal, add three object literals. In other words, the objects array should have three values. Each object should have 2 property/value pairs."

Jesus Mendoza
Jesus Mendoza
23,288 Points

You have to add three javascript objects to the array like var arr = [1, 2, 3] but instead numbers, objects. If you don't know how to create an object, I recommend you to watch the previous videos.

Good luck!

3 Answers

Just like in the preceding video:

var objects = [{question: "How", answer: 12}, {question: "When", answer: 6}, {question: "Where", answer: 14}];

Just like in the preceding video:

var objects = [{question: "How", answer: 12}, {question: "When", answer: 6}, {question: "Where", answer: 14}];
Julie Myers
Julie Myers
7,627 Points
// example of an object literal:
var myObject = {
   name: "Alice",
   age: 28,
   getName: function(){
      return this.name;
   }
}

// example of an array literal:
var myArray = [1, 2, 3, "apple"]


// putting an object literal inside of an array literal:
var myArrayLiteral = [
     {name: "Alice", age: 28}
     {instrument: "tuba", tones: "low"}
]

There are different ways of making an object. There are different ways of making an array. The examples above show how to create an object and an array the literal way.