1

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);
1
  • the .jpg part of newborn_set01_03.jpg is probably throwing off the program.... well, actually the "." of the .jpg Commented Dec 4, 2012 at 2:07

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.