Reputation: 10649
I have the following object data:
var js_images = {
"newborn_set01_01.jpg":{"filename":"newborn_set01_01.jpg","title":"First Pic","description":"First description..."},
"newborn_set01_02.jpg":{"filename":"newborn_set01_02.jpg","title":"Second Pic","description":"Second description"},
"newborn_set01_03.jpg":{"filename":"newborn_set01_03.jpg","title":"Third Pic","description":"Third description"}
};
How would I do something as simple as creating an alert to show the description of newborn_set01_03.jpg
?
This obviously doesnt work:
alert(js_images.newborn_set01_03.jpg.description);
Upvotes: 1
Views: 80
Reputation:
In addition to dot notation, you can access object members using bracket notation:
alert(js_images["newborn_set01_03.jpg"].description);
Documentation: MDN - Member Operators
Upvotes: 4