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 trialVic Mercier
3,276 Pointsarray and object mix with array
Can we do that: var message = [ { var person= { name:"Victor" }; }
];
1 Answer
Kjetil Lorentzen
13,360 PointsHi Vic,
It is not necessary to specify "var person" inside your object literals. You only needto specify the key-value paiors inside the object literals. Separate each object in the array by commas.
For this case it would be sufficient to write:
Var message = [
//Object 1
{
Name: Victor
},
//Object 2
{
Key1: value1
}
]
The above would create an array holding two objects. It may be expanded to hold any number of objects, and each object may have different key-value pairs.
Hope this answered your questions :)
Regards, Kjetil