0

I have a json object:

{"images":{"2":"building.jpg","3":"campus.jpg","4":"grads.jpg","5":"trio.jpg"},"videos":[]}  

I'm using this code to get the number of images:

var imgCount = Object.keys(obj.images).length;

But how do I get the values of those images (building.jpg, etc.)? I confess I'm having a hard time with this.

1 Answer 1

3

I do not know if this is the solution you are looking for, but you can access them, in this case, like

obj.images["2"] //"building.jpg"
obj.images["3"] //"campus.jpg"
obj.images["4"] //"grads.jpg"
obj.images["5"] //"trio.jpg"

Keep in mind that there is nothing unusual happening here. You are accessing an object through it's property's name. In this case, the object is obj.images, and the property names are 2, 3, 4 and 5.

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.