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

Rebecca Collins
PRO
Rebecca Collins
Pro Student 3,871 Points

Array of objects

I am trying to create an array with objects inside of it. I tried the code below and it's giving me a parse error... stack overflow is suggesting I use the array.push() method but this is the example I was given in Treehouse for how to initialize them together. Any suggestions?

var objects =[ { letter: 'a';, number: 1; }, { letter: 'b';, number: 2; }, { letter: 'c';, number: 3; }

];

script.js
var objects =[
  { 
    letter: 'a';,
    number: 1;
  },
  {
    letter: 'b';,
    number: 2;
  },
  {
    letter: 'c';,
    number: 3;
  }

];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
195,561 Points

The error is caused by the semicolon characters inside the objects, which are not part of object syntax.

Remove the semicolons (except for the one at the end of the assignment) and you will pass the challenge.

Rebecca Collins
Rebecca Collins
Pro Student 3,871 Points

AHH! Thank you so much, It's always something simple! haha