2012-12-04 85 views
1

我有以下對象的數據:如何打印此javascript對象?

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"} 
}; 

我怎麼會做如創建一個警報,以顯示newborn_set01_03.jpg描述簡單的東西?

這顯然不工作:

alert(js_images.newborn_set01_03.jpg.description); 
+0

的.JPG newborn_set01_03的一部分.jpg可能會推掉程序....呃,實際上是「。」 .jpg – robert

回答

4

除了點記號,你可以使用括號記號訪問對象成員:

alert(js_images["newborn_set01_03.jpg"].description); 

文檔:MDN - Member Operators

+0

太棒了!謝謝。 – JROB