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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jonathan Grieve](https://uploads.teamtreehouse.com/production/profile-photos/601842/micro_twitterCover.png)
Jonathan Grieve
Treehouse Moderator 91,253 PointsCombining Object Literals with Array Literals
I've just finished the first part of Dave's challenge. And I was almost there... I'm reay to move on but I just wondered. Why do we not give name for each object in the array literal
var students [
student1 = {
name: "Jonnie",
age: 14,
track: "Web Design",
achievements: 54,
points: 45345
},
student2 = {
name: "Jonnie",
age: 45,
track: "PHP",
achievements: 54,
points: 45345
},
Dave's solution was more like this.
var sudents = [
{
name: "Jonnie",
age: 34,
track: "Front End Track",
achievements: 54,
points: 45345},
},
{
name: "Dave",
age: 25,
track: "Front End Track",
achievements: 54,
points: 45345
}
]
(I surreptitiously added an age key.)
Why is this? I'm pretty sure that if you were creating an object on it's own you'd give it a name. :-) Thanks.
2 Answers
![Greg Kaleka](https://secure.gravatar.com/avatar/54c2cac346df05d7b70cc0a6825c1cba?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Greg Kaleka
39,021 PointsHey Jonathan,
Interesting question! The way I see it, your solution is almost analogous to an associative array or dictionary, while Dave's is a simple array. The use case will define which solution is better.
Best,
Greg
![Jonathan Grieve](https://uploads.teamtreehouse.com/production/profile-photos/601842/micro_twitterCover.png)
Jonathan Grieve
Treehouse Moderator 91,253 PointsThanks Greg, so I guess both solutions would work and I'd maybe do best to follow Dave's model? :_
![Greg Kaleka](https://secure.gravatar.com/avatar/54c2cac346df05d7b70cc0a6825c1cba?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Greg Kaleka
39,021 PointsYeah, I'm not sure what context this is in, but if it's a course, it's probably best to just use the method Dave is using so you can follow along more easily :)