简体   繁体   中英

How to print this javascript object?

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM