我有以下对象数据:
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 :(得分:4)
除了点表示法,您还可以使用括号表示法访问对象成员:
alert(js_images["newborn_set01_03.jpg"].description);